Problem in displaying data.
-
Hi, I am mani. I have a problem in display the data in datagrid. What i did is I am creating a form and in this form i created a 6 textboxes and one search button. whenever the user enter a text in textbox i retrieve the data from the database and displayed in the datagrid. The problem is when the user again enter the text in text box the datagrid is filled with new data and last data will be lost. But i want that newly searching data should be displayed in datagrid including the last searching data. This is my problem i sent last time to this portal. i got some answers. But using the DataTable i didnt get the answer. I write my code here. please tell me what is the wrong i did it in this. 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; public partial class AdvanceSearch : System.Web.UI.Page { SqlConnection con; SqlCommand cmd; SqlDataAdapter adptr; DataTable dt; DataView dv; protected void Page_Load(object sender, EventArgs e) { if (Session["mani"] == null) { dt = new DataTable(); Session["mani"] = dt; } else { dt = (DataTable)Session["mani"]; } dv = new DataView(dt); SearchResultGrid.DataSource = dv; SearchResultGrid.DataBind(); } protected void ButtonSearch_Click(object sender, EventArgs e) { con = new SqlConnection("Data Source=MVB;Initial Catalog=Communication; Integrated Security=True"); string select_query = "SELECT *FROM CommunicationDetails WHERE CommunicationId=@comid OR IssueType=@issue OR RegionName=@regname OR ApplicationName=@appname OR Descript=@Desc OR CommunicationDate=@comdate"; cmd = new SqlCommand(select_query, con); cmd.Parameters.Add("@comid", TextBoxCommunicationID.Text); cmd.Parameters.Add("@issue", TextIssueType.Text); cmd.Parameters.Add("@regname", TextBoxRegionName.Text); cmd.Parameters.Add("@appname", TextBoxApplicationName.Text); cmd.Parameters.Add("@Desc", TextBoxDescription.Text); cmd.Parameters.Add("@comdate", TextBoxDate.Text); try { con.Open(); adptr = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adptr.Fill(ds); dt
-
Hi, I am mani. I have a problem in display the data in datagrid. What i did is I am creating a form and in this form i created a 6 textboxes and one search button. whenever the user enter a text in textbox i retrieve the data from the database and displayed in the datagrid. The problem is when the user again enter the text in text box the datagrid is filled with new data and last data will be lost. But i want that newly searching data should be displayed in datagrid including the last searching data. This is my problem i sent last time to this portal. i got some answers. But using the DataTable i didnt get the answer. I write my code here. please tell me what is the wrong i did it in this. 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; public partial class AdvanceSearch : System.Web.UI.Page { SqlConnection con; SqlCommand cmd; SqlDataAdapter adptr; DataTable dt; DataView dv; protected void Page_Load(object sender, EventArgs e) { if (Session["mani"] == null) { dt = new DataTable(); Session["mani"] = dt; } else { dt = (DataTable)Session["mani"]; } dv = new DataView(dt); SearchResultGrid.DataSource = dv; SearchResultGrid.DataBind(); } protected void ButtonSearch_Click(object sender, EventArgs e) { con = new SqlConnection("Data Source=MVB;Initial Catalog=Communication; Integrated Security=True"); string select_query = "SELECT *FROM CommunicationDetails WHERE CommunicationId=@comid OR IssueType=@issue OR RegionName=@regname OR ApplicationName=@appname OR Descript=@Desc OR CommunicationDate=@comdate"; cmd = new SqlCommand(select_query, con); cmd.Parameters.Add("@comid", TextBoxCommunicationID.Text); cmd.Parameters.Add("@issue", TextIssueType.Text); cmd.Parameters.Add("@regname", TextBoxRegionName.Text); cmd.Parameters.Add("@appname", TextBoxApplicationName.Text); cmd.Parameters.Add("@Desc", TextBoxDescription.Text); cmd.Parameters.Add("@comdate", TextBoxDate.Text); try { con.Open(); adptr = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adptr.Fill(ds); dt
One possibility is that when you make a new query: - save the last results in a datatable 1 (the currently binded datatable) - execute a new query - from the query save the results to datatable 2 - merge datatable 1 and 2 to datatable 3 - bind the datatable 3 to the grid You can do this with two datatables also if you want. For information about Merge, see http://msdn.microsoft.com/en-us/library/fk68ew7b.aspx[^]
The need to optimize rises from a bad design.My articles[^]