I have to develope Jquery chat application Like Gmail in My Web application. For this i spend My lots of hours in Googling. AT THE time of searching I got one script. which is very helpful. But in the script author has used all the members
who has logged will be appeared in the chat box. instead of this i have to put only the members who's are in the friendlist. i have to show only these members.
Following is the project from where i get script.
As well as in the code author has passed dynamic userid to session but i have to pass actuall userid from database.
http://aspnetjquerychat.codeplex.com/
from Here I download the code. but the code is in the 3.5 framework. i m using 2.0 framwork. so most of the code I have changed but not getting how to make changes for list.
Please help me to solve the Problem.
Thanks In Advance
Omkar
....
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
Before changing any code, In my opinion, it would be much better to stay with .net 3.5.
here are a few thoughts :
you have the same language features in .net 3.5 as in .net 2.0, but in 3.5, you have support for more features, as well as more stability.
On the other hand, asp.net is still at 2.0 version. There's no asp.net 3.5 version, it's just a way of saying that we are using .net 3.5.
ASP.NET has moved from asp.net 2.0 directly to asp.net 4.0
on the other hand, .net framework has passed from .net 2.0, 3.0, then 3.5.
Let me know what you think.
Regards,
asp.net3.5jquery asp.net 3.5asp.net 3.5 C#jquery ajax xml
No Problem. If I Kept the same code. will it make any problem in application when i'll upload it on server.
if no then it's ok. i'll keep the code same. but my another problem is that i have to show only friends in the list. but I am Not getting how to Put. how to create query for this. because I m Aware of Linq thats Why I m not getting how to set friends in
the list.
Please help me to solve this issue.
Thanks
Omkar.
....
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
For .NET, if you don't have .net 3.5 version on the server, it might not work. I have installed .net 3.5 on different integration servers. Make sure you do it right though. if you go back to .net 2.0, you will lose the LINQ features used in the chat applications.
On the other hand, for a friend's list, you need to add some custom code, in order to be able to have a friends list, as I don't see a category for users. All users are not categorized.
A good understanding of LINQ to XML and n-tier development is needed to handle this modification. you need to add a field to UserChatSession for category; Then filter it in the queries.
The way the application works, is by creating a session, and building the list of users dynamically, storing it in memory. in the web.config, you can change the InMemory attribute in appsettings to False, then, the application will create users in an xml
file. It is faster to avoid writing on disc, yet, for clarity, go ahead and do it.
Then, in the Data Folder you will find your xml files.
Integrating the chat application into another, is not a simple task. you have to go step by step, and also, always have the sample application running alone before you integrate it.
if you get errors, try and post them here and in the forum too.
Try this in the application (original version) and let me know
I m getting frustedted because i don't have knowledge of linq because of this is I am Unable to create query for this. because of this I Am Not able to filter only peoples in my friendlist in the chat box.
Please help me to solve this problem
Thanks in advance.
Omkar.
....
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
Friend i need a little help. can you send me the original source code of http://aspnetjquerychat.codeplex.com/ project.I am asking it because now that project is unavailble.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
public partial class _Default : System.Web.UI.Page
{
//protected string jsonDateNow;
chatBiz objchatBiz = new chatBiz();
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
if (!IsPostBack)
{
// jsonDateNow = new JavaScriptSerializer().Serialize(DateTime.Now);
Bindddl();
txtLoginName.Text = User.Identity.Name.ToString();
txtLoginUserID.Text= Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString();
}
}
else
{
Response.Redirect("AccessDenied.aspx");
}
}
private void Bindddl()
{
DataView dv = objchatBiz.GetUserNames();
ddlTouser.DataSource = dv;
ddlTouser.DataTextField = "UserName";
ddlTouser.DataValueField = "UserId";
ddlTouser.DataBind();
ddlTouser.Items.Insert(0, "Select");
ddlTouser.Items[0].Value = "0";
}
[System.Web.Services.WebMethod]
public static string Insert(string Message, string FromUser, string ToUser)
{
chatBiz objchatBiz = new chatBiz();
objchatBiz.InsertChat(Message, FromUser, ToUser, false);
return "";
}
[System.Web.Services.WebMethod]
public static ArrayList Chatmessage(string Touserid)
{
chatBiz objchatBiz = new chatBiz();
ArrayList list = new ArrayList();
list = objchatBiz.GetMessage(Touserid);
return list;
}
[System.Web.Services.WebMethod]
public static void Updatemessage(string Touserid)
{
chatBiz objchatBiz = new chatBiz();
objchatBiz.UpdateReadmessage(Touserid);
}
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data.SqlClient;
/// <summary>
/// Summary description for chatBiz
/// </summary>
public class chatBiz
{
string connection = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
public chatBiz()
{
//
// TODO: Add constructor logic here
//
}
public void InsertMessage(int FromUserId,int ToUserId,string Message)
{
using (SqlConnection con = new SqlConnection(connection))
{
string Insert = @"INSERT INTO tblMessage (Messagetext, FromUser, ToUser, IsReaded)
VALUES (@Messagetext, @FromUser, @ToUser,0)";
SqlCommand cmd = new SqlCommand(Insert, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Messagetext", Message);
cmd.Parameters.AddWithValue("@FromUser", FromUserId);
cmd.Parameters.AddWithValue("@ToUser", ToUserId);
con.Open();
cmd.ExecuteNonQuery();
}
}
public ArrayList GetMessage(string Touserid)
{
ArrayList list = new ArrayList();
String strConnString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
String strQuery = "SELECT * FROM [tblMessage] WHERE [ToUser] ='" + Touserid + "' and IsReaded='False'";
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
//cmd.Parameters.AddWithValue("@ContinentID", cityid);
cmd.CommandText = strQuery;
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
list.Add(new ListItem(
sdr["Messagetext"].ToString(),
sdr["MessageID"].ToString()
));
}
con.Close();
return list;
}
}
}
public void UpdateReadmessage(string Touserid)
{
using (SqlConnection con = new SqlConnection(connection))
{
string StatusUpate = string.Format(@"update tblMessage set IsReaded='" + true + "' where ToUser='" + Touserid+"'");
SqlCommand cmd = new SqlCommand(StatusUpate, con);
con.Open();
cmd.ExecuteNonQuery();
}
}
public void InsertChat(string Message, string FromUser, string ToUser, bool IsReaded)
{
using (SqlConnection con = new SqlConnection(connection))
{
string Insert = @"INSERT INTO tblMessage (Messagetext, FromUser, ToUser, IsReaded)
VALUES (@Messagetext, @FromUser, @ToUser, @IsReaded)";
SqlCommand cmd = new SqlCommand(Insert, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Messagetext", Message);
cmd.Parameters.AddWithValue("@FromUser", FromUser);
cmd.Parameters.AddWithValue("@ToUser", ToUser);
cmd.Parameters.AddWithValue("@IsReaded", IsReaded);
con.Open();
cmd.ExecuteNonQuery();
}
}
public DataView GetUserNames()
{
using (SqlConnection cn = new SqlConnection(connection))
{
string shippingmethod = @"select * from aspnet_Users";
SqlDataAdapter da = new SqlDataAdapter(shippingmethod, cn);
DataSet dsProducts = new DataSet();
cn.Open();
da.Fill(dsProducts);
return dsProducts.Tables[0].DefaultView;
}
}
}
database script
/****** Object: Table [dbo].[tblUser] Script Date: 09/14/2011 21:49:57 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tblUser]') AND type in (N'U'))
DROP TABLE [dbo].[tblUser]
GO
/****** Object: Table [dbo].[tblMessage] Script Date: 09/14/2011 21:49:57 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tblMessage]') AND type in (N'U'))
DROP TABLE [dbo].[tblMessage]
GO
/****** Object: Table [dbo].[tblMessage] Script Date: 09/14/2011 21:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tblMessage]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tblMessage](
[MessageID] [int] IDENTITY(1,1) NOT NULL,
[Messagetext] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FromUser] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ToUser] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IsReaded] [bit] NULL,
CONSTRAINT [PK__tblMessage__7C8480AE] PRIMARY KEY CLUSTERED
(
[MessageID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
END
GO
/****** Object: Table [dbo].[tblUser] Script Date: 09/14/2011 21:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tblUser]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tblUser](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[UserName] [varchar](300) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
END
GO
Please excuse my poor/bad English
***DON'T FORGET TO CLICK “MARK AS ANSWER” ON THE POST IF HELPED YOU.
omkar.mhaisk...
Member
79 Points
85 Posts
Need Help in creating chat application using jquery.
Aug 17, 2010 05:06 AM|LINK
Hello Friends
I have to develope Jquery chat application Like Gmail in My Web application. For this i spend My lots of hours in Googling. AT THE time of searching I got one script. which is very helpful. But in the script author has used all the members who has logged will be appeared in the chat box. instead of this i have to put only the members who's are in the friendlist. i have to show only these members.
Following is the project from where i get script.
As well as in the code author has passed dynamic userid to session but i have to pass actuall userid from database.
http://aspnetjquerychat.codeplex.com/
from Here I download the code. but the code is in the 3.5 framework. i m using 2.0 framwork. so most of the code I have changed but not getting how to make changes for list.
Please help me to solve the Problem.
Thanks In Advance
Omkar
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
formationusa
Participant
1290 Points
215 Posts
Re: Need Help in creating chat application using jquery.
Aug 17, 2010 07:59 AM|LINK
Hello omkar,
Before changing any code, In my opinion, it would be much better to stay with .net 3.5.
here are a few thoughts :
you have the same language features in .net 3.5 as in .net 2.0, but in 3.5, you have support for more features, as well as more stability.
On the other hand, asp.net is still at 2.0 version. There's no asp.net 3.5 version, it's just a way of saying that we are using .net 3.5.
ASP.NET has moved from asp.net 2.0 directly to asp.net 4.0
on the other hand, .net framework has passed from .net 2.0, 3.0, then 3.5.
Let me know what you think.
Regards,
asp.net3.5 jquery asp.net 3.5 asp.net 3.5 C# jquery ajax xml
http://oudinia.blogspot.com
omkar.mhaisk...
Member
79 Points
85 Posts
Re: Need Help in creating chat application using jquery.
Aug 17, 2010 09:00 AM|LINK
Ok sir.
No Problem. If I Kept the same code. will it make any problem in application when i'll upload it on server.
if no then it's ok. i'll keep the code same. but my another problem is that i have to show only friends in the list. but I am Not getting how to Put. how to create query for this. because I m Aware of Linq thats Why I m not getting how to set friends in the list.
Please help me to solve this issue.
Thanks
Omkar.
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
formationusa
Participant
1290 Points
215 Posts
Re: Need Help in creating chat application using jquery.
Aug 17, 2010 09:44 AM|LINK
Hello omkar,
For .NET, if you don't have .net 3.5 version on the server, it might not work. I have installed .net 3.5 on different integration servers. Make sure you do it right though. if you go back to .net 2.0, you will lose the LINQ features used in the chat applications.
On the other hand, for a friend's list, you need to add some custom code, in order to be able to have a friends list, as I don't see a category for users. All users are not categorized.
A good understanding of LINQ to XML and n-tier development is needed to handle this modification. you need to add a field to UserChatSession for category; Then filter it in the queries.
The way the application works, is by creating a session, and building the list of users dynamically, storing it in memory. in the web.config, you can change the InMemory attribute in appsettings to False, then, the application will create users in an xml file. It is faster to avoid writing on disc, yet, for clarity, go ahead and do it.
Regards,
http://oudinia.blogspot.com
omkar.mhaisk...
Member
79 Points
85 Posts
Re: Need Help in creating chat application using jquery.
Aug 17, 2010 02:14 PM|LINK
Hello Sir.
I have tried but as i said I new bew and also learning that concept. but not good in it.
So thats why I want some help from who are expert in this area. when i m try implement it in my project i m getting lots of error.
and don't know hhow to solve this error.
If Possible tell me where and what to change in the code.
Thanks And Regards
Omkar
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
formationusa
Participant
1290 Points
215 Posts
Re: Need Help in creating chat application using jquery.
Aug 17, 2010 03:43 PM|LINK
This is where you change the property to False in the web.config
<appSettings> <add key="InMemory" value="False"></add> </appSettings>Then, in the Data Folder you will find your xml files.
Integrating the chat application into another, is not a simple task. you have to go step by step, and also, always have the sample application running alone before you integrate it.
if you get errors, try and post them here and in the forum too.
Try this in the application (original version) and let me know
http://oudinia.blogspot.com
omkar.mhaisk...
Member
79 Points
85 Posts
Re: Need Help in creating chat application using jquery.
Aug 19, 2010 07:40 AM|LINK
Hello Sir
I have try to devlope this is my application.
And almost all the issue I have solved it. but except friendlist.
Because i tried to use break point for checking not getting from where does he put all the toghtther all the session members.
Thanks And Regards
Omkar
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
omkar.mhaisk...
Member
79 Points
85 Posts
Re: Need Help in creating chat application using jquery.
Aug 26, 2010 05:45 AM|LINK
Hello Friends
I m getting frustedted because i don't have knowledge of linq because of this is I am Unable to create query for this. because of this I Am Not able to filter only peoples in my friendlist in the chat box.
Please help me to solve this problem
Thanks in advance.
Omkar.
Omkar Mhaiskar
Pune India
Omya.4u@gmail.com
Don't forget to "Mark as Answer" on the post, if it helps you.
chapneox
Member
6 Points
3 Posts
Re: Need Help in creating chat application using jquery.
Sep 14, 2011 03:45 PM|LINK
Hi omkar.mhaiskar
Friend i need a little help. can you send me the original source code of http://aspnetjquerychat.codeplex.com/ project.I am asking it because now that project is unavailble.
thanks.
ucsccbjp@live.com
abiruban
All-Star
16320 Points
2773 Posts
Re: Need Help in creating chat application using jquery.
Sep 14, 2011 04:21 PM|LINK
hi u can try my chat application
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="Scripts/json2-min.js" type="text/javascript"></script> <script type="text/javascript"> </script> <script type="text/javascript"> $(document).ready(function () { chat(); //updateMessage(); }); function timeMsg() { var t = setTimeout("chat()", 10000); // var y = setTimeout("updateMessage()", 1000); } function chat() { timeMsg(); var Touserid = $("#<%=ddlTouser.ClientID%>").val(); var Fromuserid = $("#<%=txtLoginUserID.ClientID%>").val(); var Tousername = $("#<%=ddlTouser.ClientID%> option:selected").text(); var pageUrl = '<%=ResolveUrl("~/Default.aspx")%>' $.ajax({ type: "POST", url: pageUrl + '/Chatmessage', data: '{Touserid: "' + Fromuserid + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { for (var i = 0; i < data.d.length; i++) { $("#tblImage").append("<tr><td>" + Tousername + ":" + data.d[i].Text + " </td></tr>"); } updateMessage(); } }); } function updateMessage() { var Touserid = $("#<%=ddlTouser.ClientID%>").val(); var Fromuserid = $("#<%=txtLoginUserID.ClientID%>").val(); var pageUrl = '<%=ResolveUrl("~/Default.aspx")%>' $.ajax({ type: "POST", url: pageUrl + '/Updatemessage', data: '{Touserid: "' + Fromuserid + '"}', contentType: "application/json; charset=utf-8", dataType: "json" }); } </script> <script type="text/javascript"> function insertMessage() { var pageUrl = '<%=ResolveUrl("~/Default.aspx")%>' $.ajax({ type: "POST", url: pageUrl + '/Insert', data: '{Message: "' + $('#<%=txtMessage.ClientID%>').val() + '" , FromUser: "' + $('#<%=txtLoginUserID.ClientID%>').val().toString() + '", ToUser: "' + $('#<%=ddlTouser.ClientID%>').val().toString() + '"}', contentType: "application/json; charset=utf-8", dataType: "json" }); } function ddd() { $("#<%=txtMessage.ClientID%>").val(""); // var Name = $("#<%=txtLoginName.ClientID%>").val(); // $("#tblImage").append("<tr><td>" + Name + ":" +$('#<%=txtMessage.ClientID%>').val() // + " </td></tr>"); } </script> <div> <table> <tr> <td> LoginUserName </td> <td> <asp:TextBox ID="txtLoginName" runat="server"></asp:TextBox> <p style=" display:none"> <asp:TextBox ID="txtLoginUserID" runat="server"></asp:TextBox></p> </td> </tr> <tr> <td> ToUserID </td> <td> <asp:DropDownList ID="ddlTouser" runat="server"> </asp:DropDownList> </td> </tr> </table> <table border="1px" > <tr> <td colspan="2" style="height:200px" > <table id="tblImage"> </table> </td> </tr> <tr> <td> <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox> </td> <td> <%--<asp:Button ID="btnSend" runat="server" Text="Send" />--%> <input id="btnSend" onclick="insertMessage();ddd();chat(); " type="button" value="Send" /> </td> </tr> </table> </div> </asp:Content>using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Web.Services; using System.Data.SqlClient; using System.Web.Script.Serialization; public partial class _Default : System.Web.UI.Page { //protected string jsonDateNow; chatBiz objchatBiz = new chatBiz(); protected void Page_Load(object sender, EventArgs e) { if (User.Identity.IsAuthenticated) { if (!IsPostBack) { // jsonDateNow = new JavaScriptSerializer().Serialize(DateTime.Now); Bindddl(); txtLoginName.Text = User.Identity.Name.ToString(); txtLoginUserID.Text= Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString(); } } else { Response.Redirect("AccessDenied.aspx"); } } private void Bindddl() { DataView dv = objchatBiz.GetUserNames(); ddlTouser.DataSource = dv; ddlTouser.DataTextField = "UserName"; ddlTouser.DataValueField = "UserId"; ddlTouser.DataBind(); ddlTouser.Items.Insert(0, "Select"); ddlTouser.Items[0].Value = "0"; } [System.Web.Services.WebMethod] public static string Insert(string Message, string FromUser, string ToUser) { chatBiz objchatBiz = new chatBiz(); objchatBiz.InsertChat(Message, FromUser, ToUser, false); return ""; } [System.Web.Services.WebMethod] public static ArrayList Chatmessage(string Touserid) { chatBiz objchatBiz = new chatBiz(); ArrayList list = new ArrayList(); list = objchatBiz.GetMessage(Touserid); return list; } [System.Web.Services.WebMethod] public static void Updatemessage(string Touserid) { chatBiz objchatBiz = new chatBiz(); objchatBiz.UpdateReadmessage(Touserid); } }using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; using System.Collections; using System.Web.UI.WebControls; using System.Web.Services; using System.Data.SqlClient; /// <summary> /// Summary description for chatBiz /// </summary> public class chatBiz { string connection = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; public chatBiz() { // // TODO: Add constructor logic here // } public void InsertMessage(int FromUserId,int ToUserId,string Message) { using (SqlConnection con = new SqlConnection(connection)) { string Insert = @"INSERT INTO tblMessage (Messagetext, FromUser, ToUser, IsReaded) VALUES (@Messagetext, @FromUser, @ToUser,0)"; SqlCommand cmd = new SqlCommand(Insert, con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Messagetext", Message); cmd.Parameters.AddWithValue("@FromUser", FromUserId); cmd.Parameters.AddWithValue("@ToUser", ToUserId); con.Open(); cmd.ExecuteNonQuery(); } } public ArrayList GetMessage(string Touserid) { ArrayList list = new ArrayList(); String strConnString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; String strQuery = "SELECT * FROM [tblMessage] WHERE [ToUser] ='" + Touserid + "' and IsReaded='False'"; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; //cmd.Parameters.AddWithValue("@ContinentID", cityid); cmd.CommandText = strQuery; cmd.Connection = con; con.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { list.Add(new ListItem( sdr["Messagetext"].ToString(), sdr["MessageID"].ToString() )); } con.Close(); return list; } } } public void UpdateReadmessage(string Touserid) { using (SqlConnection con = new SqlConnection(connection)) { string StatusUpate = string.Format(@"update tblMessage set IsReaded='" + true + "' where ToUser='" + Touserid+"'"); SqlCommand cmd = new SqlCommand(StatusUpate, con); con.Open(); cmd.ExecuteNonQuery(); } } public void InsertChat(string Message, string FromUser, string ToUser, bool IsReaded) { using (SqlConnection con = new SqlConnection(connection)) { string Insert = @"INSERT INTO tblMessage (Messagetext, FromUser, ToUser, IsReaded) VALUES (@Messagetext, @FromUser, @ToUser, @IsReaded)"; SqlCommand cmd = new SqlCommand(Insert, con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Messagetext", Message); cmd.Parameters.AddWithValue("@FromUser", FromUser); cmd.Parameters.AddWithValue("@ToUser", ToUser); cmd.Parameters.AddWithValue("@IsReaded", IsReaded); con.Open(); cmd.ExecuteNonQuery(); } } public DataView GetUserNames() { using (SqlConnection cn = new SqlConnection(connection)) { string shippingmethod = @"select * from aspnet_Users"; SqlDataAdapter da = new SqlDataAdapter(shippingmethod, cn); DataSet dsProducts = new DataSet(); cn.Open(); da.Fill(dsProducts); return dsProducts.Tables[0].DefaultView; } } }***DON'T FORGET TO CLICK “MARK AS ANSWER” ON THE POST IF HELPED YOU.