I am new user in C# ,I am developing a message pool means like a Facebook when we click on above message icon all message show in list .then click on the sender name all message show that person. For
That kind of message poll am developed two pages one page is sender and the other one is receiver .when I send message from sender page it will be saved into data base and show into other pages text box.
Now problem is that the receiver pages cannot show all messages .it will show one first message which are saved into data base.
I want it will show all messages which are sending from sender page. Please help me to solve that problem, thanks in advance below my all code.
WebForm1.aspx.css
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace MessageShow
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox2.Text == "")
{
Response.Redirect("Please Enter your Message");
}
else
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO tbl_message(Message) VALUES(@Message)"))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Message", TextBox2.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
}
Webform2.aspx.css
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace MessageShow
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand com;
string str;
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from tbl_message";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
if (reader.Read())
{
TextBox1.Text = reader["Message"].ToString();
reader.Close();
con.Close();
}
}
}
}
}
Data base Table
tbl_message
Field Name
|
Data type
|
Allow
|
ID
|
int
|
Identity true(primary key)
|
Message
|
Varchar(50)
|
Allow null
|