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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manas MohapatraRank #182 · 13.2K reputationPosted Dec 27, 2015, 2:35 AM EST
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Dec 27, 2015, 2:41 AM EST
Ashutosh Tripathi51 reputationPosted Dec 27, 2015, 2:47 AM EST
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Dec 27, 2015, 2:57 AM EST
Rupali ShindeRank #539 · 4.5K reputationPosted Dec 27, 2015, 6:20 PM EST
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();
}