Chat in mvc asp.net through razor engine
I have to integrate a chatting solution like social sites provide in their website. So i need some codes and ideas which help me to do my job. I want to save chat in database.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rupali ShindePosted Dec 27, 2015, 11:20 PM
private void SubmitNote(string message){
// Ensure parameter isn't null.
if(string.IsNullOrEmpty(message))
return;
// Our Insert Query:
string insert = @"INSERT INTO [Notes] ([Username], [Date], [Message])
VALUES (@Username, @Date, @Message);";
// Define our Connection & Command:
using(SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))
using(SqlCommand command = new SqlCommand(insert, connection)){
// Open Connection
connection.Open();
// Define our Command (AddWithValue / Add Approach)
command.Parameters.Add("@Username", SqlDbType.VarChar, 50).Values = User.Identity.Name;
command.Parameters.AddWithValue("@Date", DateTime.Now);
command.Parameters.Add("@Message", SqlDbType.VarChar).Value = message;
// Execute Query:
command.ExecuteNonQuery();
}
Afzaal Ahmad ZeeshanPosted Dec 27, 2015, 7:57 AM
Ashutosh TripathiPosted Dec 27, 2015, 7:47 AM
Afzaal Ahmad ZeeshanPosted Dec 27, 2015, 7:41 AM
Manas MohapatraPosted Dec 27, 2015, 7:35 AM