sqlCommandBuilder update not working as expected - c#

I'm trying to do an update using CommandBuilder. The code works perfectly when the the code fetching the data is retrieved by a button command, but when I fetch the data from the page_load, update fails.
The program simply fetches data from a database then uses the sqlCommandBuilder to make updates on a specific table.
I can't figure out what is going on.
Here is is the Code that fails.
private Users users;
protected void Page_Load(object sender, EventArgs e)
{
users = (Users)Session["Users"];
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
string selectQuery = "Select * from Candidate where Candidate_ID = " + users.Candidate_ID;
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectQuery, connection);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "Candidates");
ViewState["DATASET"] = dataSet;
ViewState["SELECT_QUERY"] = selectQuery;
if (dataSet.Tables["Candidates"].Rows.Count > 0)
{
DataRow dataRow = dataSet.Tables["Candidates"].Rows[0];
txtLastName.Text = dataRow["LastName"].ToString();
txtCity.Text = dataRow["City"].ToString();
ddlGender.SelectedValue = dataRow["Gender"].ToString();
lblStatus.Text = "";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "No record with ID = " + txtCandidateID.Text;
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = new SqlCommand((string)ViewState["SELECT_QUERY"], con);
SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);
DataSet ds = (DataSet)ViewState["DATASET"];
DataRow dr = ds.Tables["Candidates"].Rows[0];
dr["LastName"] = txtLastName.Text;
dr["Gender"] = ddlGender.SelectedValue;
dr["City"] = txtCity.Text;
int rowsUpdated = dataAdapter.Update(ds, "Candidates");
if (rowsUpdated == 0)
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "No rows updated";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = rowsUpdated.ToString() + " row(s) updated";
}
}
Here is the code that works perfectly.
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = new SqlCommand((string)ViewState["SELECT_QUERY"], con);
SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);
DataSet ds = (DataSet)ViewState["DATASET"];
DataRow dr = ds.Tables["Candidates"].Rows[0];
dr["LastName"] = txtLastName.Text;
dr["Gender"] = ddlGender.SelectedValue;
dr["City"] = txtCity.Text;
int rowsUpdated = dataAdapter.Update(ds, "Candidates");
if (rowsUpdated == 0)
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "No rows updated";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = rowsUpdated.ToString() + " row(s) updated";
}
}
protected void btnFetchData_Click(object sender, EventArgs e)
{
users = (Users)Session["Users"];
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
string selectQuery = "Select * from Candidate where Candidate_ID = " + users.Candidate_ID;
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectQuery, connection);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "Candidates");
ViewState["DATASET"] = dataSet;
ViewState["SELECT_QUERY"] = selectQuery;
if (dataSet.Tables["Candidates"].Rows.Count > 0)
{
DataRow dataRow = dataSet.Tables["Candidates"].Rows[0];
txtLastName.Text = dataRow["LastName"].ToString();
txtCity.Text = dataRow["City"].ToString();
ddlGender.SelectedValue = dataRow["Gender"].ToString();
lblStatus.Text = "";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "No record with ID = " + txtCandidateID.Text;
}
}

Did you miss a check on Page.IsPostBack?
Remember that in ASP.NET when you click a server button the code in the Page_Load is called before the code in the button click event.
Without
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
// load data
}
}
the code that reloads the DATASET is executed again and, when you receive the control in the button click event, your changes are lost.

fisrt of all make a debug of your source code.
Create breakpoint on each line and check which values are stored in varibales.
Also make it for debug purpouse in a try catch block.
When you can understand where the error has been made you may check of to fix issue.
Which type of error you receive??
Another stuff you assume that user is always in session.Take care that aspnet use a custom method to recycle session and you can have session empty because iis application pool is restarted of has reached is "limit"
is a good practice check if session(value) is null before make the cast

Related

In the below code I want to add if statement for GridViewBind() where in the else case I want to say "NO DATA TO DISPLAY"

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
SqlDataAdapter dadapter;
DataSet dset; "SELECT Buildingsection from Building_Section";// Another Table
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dadapter = new SqlDataAdapter(sql, con);
dset = new DataSet();
dadapter.Fill(dset);
DropDownList1.DataSource = dset.Tables[0];
DropDownList1.DataTextField = "Buildingsection ";
DropDownList1.DataValueField = "Buildingsection ";
DropDownList1.DataBind();
GridViewBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewBind();
}
public void GridViewBind()
{
dadapter = new SqlDataAdapter("SELECT * from SocoetyMaintan where Id=" + DropDownList1.SelectedValue + "", con);
dset = new DataSet();
dadapter.Fill(dset);
GridView1.DataSource = dset.Tables[0];
GridView1.DataBind();
You can create another text field/control with text “NO DATA TO DISPLAY”. It will be hidden by default. Show it when condition does not satisfy and hide the grid.
Otherwise clean up the gridview data and insert the text “NO DATA TO DISPLAY” in first entry.
This code worked to solve the problem for me:
if (dset.Tables[0].Rows.Count == 0)
{
Label1.Visible = true;
Label1.Text = "No Data To Display!";
}
else Label1.Visible = false;

How to store values in drop down list after button click in asp.net?

I have created 2 DropDownLists First dropdown contains "TeamName" and second one contain "TeamMember" name. The requirement is when we select particular TeamName from dropdown second dropdown should automatic populates the team member name and after button click data should be inserted in database,It works fine for first button click but second time on the same page "TeamName" dropdown does not show name of department,suddenly it gets lost.So Please suggest me what I need to do to resolve this issue??
Following is the code which I did to achieve this task
User.aspx page code:
User.aspx.cs page code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindTeamName();
txtCurrentDate.Text = DateTime.Now.ToString("MM-dd-yyyy");
txtCurrentDate.ForeColor = System.Drawing.Color.Green;
}
}
private void BindTeamName()
{
SqlConnection con = new SqlConnection(SqlString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from TeamName", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl1.DataSource = ds;
ddl1.DataTextField = "TeamName";
ddl1.DataValueField = "TeamId";
ddl1.DataBind();
ddl1.Items.Insert(0, new ListItem("--Select--", "0"));
}
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
int TeamId = Convert.ToInt32(ddl1.SelectedValue);
SqlConnection con = new SqlConnection(SqlString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from TeamResource where TeamId=" + TeamId, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl2.DataSource = ds;
ddl2.DataTextField = "EmpName";
ddl2.DataValueField = "EmpId";
ddl2.DataBind();
ddl2.Items.Insert(0, new ListItem("--Select--", "0"));
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
using (SqlConnection con = new SqlConnection(SqlString))
{
SqlCommand cmd = new SqlCommand("InsertUserData", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#WorkDate", txtCurrentDate.Text);
cmd.Parameters.AddWithValue("#TeamName", ddl1.SelectedItem.Text);
cmd.Parameters.AddWithValue("#TeamMember", ddl2.SelectedItem.Text);
cmd.Parameters.AddWithValue("#AvailableBandwidth", ddlAvailable.SelectedItem.Value);
con.Open();
int ReturnCode = (int)cmd.ExecuteScalar();
if (ReturnCode == -1)
{
lblMsg.Text = "Already Data present";
lblMsg.ForeColor = System.Drawing.Color.Red;
ClearFields();
}
else
{
lblMsg.Text = "Data inserted successfully";
lblMsg.ForeColor = System.Drawing.Color.Green;
ClearFields();
}
}
I would re-bind the "TeamName" dropdown list after a successful save.
//btnSubmit_Click
if (ReturnCode == -1)
{
lblMsg.Text = "Already Data present";
lblMsg.ForeColor = System.Drawing.Color.Red;
ClearFields();
}
else
{
lblMsg.Text = "Data inserted successfully";
lblMsg.ForeColor = System.Drawing.Color.Green;
ClearFields();
BindTeamName(); //re-bind the initial dropdown so you can select a new team
}
Actually you can use that method either way, depending on what ClearFields() does.

GridView Not showing when i delete the all rows from database table

i am facing a problem do not know how to set this problem the problem is that my project working fine but when i delete all the rows from sql databse its not show grid kindly help
your response will be highly appreciated
Here is my Code Behind
public partial class Web_grid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
SqlConnection conne = new SqlConnection("Data Source=192.168.0.6;Initial Catalog=TestDataBase;Persist Security Info=True;User ID=sa;Password=malick");
DataSet ds = new DataSet();
conne.Open();
string cmdstr = "SELECT * FROM OPR1 ";
SqlCommand cmd = new SqlCommand(cmdstr, conne);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
cmd.ExecuteNonQuery();
conne.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
// GridView1.DataSource =null;
// GridView1.DataSource = ds;
// GridView1.DataBind();
//ds = null;
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
SqlConnection conne = new SqlConnection("Data Source=192.168.0.6;Initial Catalog=TestDataBase;Persist Security Info=True;User ID=sa;Password=malick");
conne.Open();
if (e.CommandName.Equals("ADD"))
{
Calendar txtOpenDate = (Calendar)GridView1.FooterRow.FindControl("txtOpenDate");
TextBox txtCloseDate = (TextBox)GridView1.FooterRow.FindControl("txtCloseDate");
DropDownList DropDownListoppr = (DropDownList)GridView1.FooterRow.FindControl("DropDownListoppr");
DropDownList DropDownListStages = (DropDownList)GridView1.FooterRow.FindControl("DropDownListStages");
TextBox txtAddLine = (TextBox)GridView1.FooterRow.FindControl("txtAddLine");
TextBox txtStages = (TextBox)GridView1.FooterRow.FindControl("txtStages");
TextBox txtAddOppId = (TextBox)GridView1.FooterRow.FindControl("txtAddOppId");
string cmdstr = "insert into OPR1(OpenDate,CloseDate,SlpCode,Step_Id,Line,OpprId) values(#txtOpenDate,#txtCloseDate,#SlpCode,#Step_Id,#txtAddLine,#txtAddOppId)";
SqlCommand cmd = new SqlCommand(cmdstr, conne);
cmd.Parameters.AddWithValue("#txtOpenDate", txtOpenDate.TodaysDate);
cmd.Parameters.AddWithValue("#txtCloseDate", txtCloseDate.Text);
cmd.Parameters.AddWithValue("#Step_Id", DropDownListStages.SelectedValue.ToString()); // SelectedItem.ToString());
cmd.Parameters.AddWithValue("#SlpCode", DropDownListoppr.SelectedValue.ToString()); // SelectedItem.ToString());
cmd.Parameters.AddWithValue("#txtStages", txtStages.Text);
cmd.Parameters.AddWithValue("#txtAddLine", txtAddLine.Text);
cmd.Parameters.AddWithValue("#txtAddOppId", txtAddOppId.Text);
cmd.ExecuteNonQuery();
// this.TextBox1.Text = DropDownList1.SelectedItem.ToString();
// this.TextBox3.Text = DropDownList1.SelectedValue.ToString();
BindData();
conne.Close();
}
}
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList DropDownListoppr = (DropDownList)e.Row.FindControl("DropDownListoppr");
DropDownList DropDownListStages = (DropDownList)e.Row.FindControl("DropDownListStages");
DataTable CardCode = new DataTable();
DataTable CardCode1 = new DataTable();
SqlConnection connection = new SqlConnection("Data Source=192.168.0.6;Initial Catalog=TestDataBase;Persist Security Info=True;User ID=sa;Password=malick");
using (connection)
{
SqlCommand theCommand = new SqlCommand("select SlpCode,SlpName from OSLP ", connection);
SqlCommand theCommand1 = new SqlCommand("select Distinct StepId, Descript from OOST ", connection);
SqlDataAdapter adapter = new SqlDataAdapter(theCommand);
SqlDataAdapter adapter1 = new SqlDataAdapter(theCommand1);
adapter.Fill(CardCode);
adapter1.Fill(CardCode1);
//DropDownList7.DataSource = CardCode;
//DropDownList7.DataTextField = "SlpName";
//DropDownList7.DataValueField = "SlpCode";
//DropDownList7.DataBind();
if (CardCode.Rows.Count > 0)
{
for (int i = 0; i < CardCode.Rows.Count; i++)
{
string name3 = CardCode.Rows[i]["SlpName"].ToString();
string slpCode = CardCode.Rows[i]["SlpCode"].ToString();
DropDownListoppr.Items.Add(new ListItem(name3, slpCode));
}
}
if (CardCode1.Rows.Count > 0)
{
for (int j = 0; j < CardCode1.Rows.Count; j++)
{
string name4 = CardCode1.Rows[j]["Descript"].ToString();
string stageCode = CardCode1.Rows[j]["StepId"].ToString();
DropDownListStages.Items.Add(new ListItem(name4, stageCode));
}
}
}
}
}
No need of cmd.ExecuteNonQuery(); in BindData Method, As you are not performing any insert,delete or update operation.
try to add this property to your aspx gridview
EmptyDataText="someText"
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatext(v=vs.110).aspx
or you can use EmptyDataTemplate - just like TemplateField
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate(v=vs.110).aspx

Error in getting items in combobox from table

Running the following code, I find that SelectedIndexChanged method runs before load method... How can I correct this? I tried resetting the events but that didn't work either
namespace adotestquestion
{
public partial class Bill : Form
{
public Bill()
{
InitializeComponent();
}
string constring = "data source=NISHANT-PC ; initial catalog=NIK_DATABASE ; user id=xxxxxx ; password=xxxxxx";
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter adapter;
DataSet ds;
DataTable dt;
int qty, tax, total, price;
private void Bill_Load(object sender, EventArgs e)
{
con = new SqlConnection(constring);
cmd = new SqlCommand("select billid from bill", con);
adapter = new SqlDataAdapter(cmd);
ds = new DataSet();
adapter.Fill(ds);
dt = ds.Tables[0];
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "billid";
comboBox1.ValueMember = "billid";
MessageBox.Show(id.ToString());
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Text);
int id;
id = Convert.ToInt32(comboBox1.Text);
con = new SqlConnection(constring);
cmd = new SqlCommand("select * from bill where billid=#id", con);
// cmd.Parameters.Add("#id", Convert.ToInt32(comboBox1.Text));
cmd.Parameters.Add("#id", id);
adapter = new SqlDataAdapter(cmd);
ds = new DataSet();
adapter.Fill(ds);
dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
textBox1.Text = dr[1].ToString();
textBox2.Text = dr[2].ToString();
textBox3.Text = dr[4].ToString();
textBox4.Text = dr[3].ToString();
textBox5.Text = dr[5].ToString();
textBox6.Text = dr[6].ToString();
textBox7.Text = dr[7].ToString();
textBox8.Text = dr[8].ToString();
textBox9.Text = dr[9].ToString();
textBox10.Text = dr[10].ToString();
}
}
}
}
Unwire the events subscription in InitializeComponent method and wire it at the end of Form_Load.
Instead of trying to change the events, etc. you can simply check if there is anything in fact selected in the combo box in your event. This will keep the code simple and will work correctly.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex >= 0)
{
// your existing code goes here
}
}
A third alternative is to create a private class-level variable like isFormLoading and set it to true initially, then set it to false at the end of your Bill_Load event.
You can check the value of the variable in comboBox1_SelectedIndexChanged and anywhere else it's needed to determine whether a block of code should run or not.
But really, any of the other provided answers will work.
Problem : whenever you bind an Items to your Combobox , SelectedIndexChanged event will be fired.
Solution : inside the SelectedIndexChanged event you need to identify wether it is fired from the Load event or due to the Item selection change.
you can declare a boolean variable ,set it to true whenever control enters into Load event.
from selectedIndexChanged event only execute the code when boolean variable is false.
Note : at the end of the Load event again change the boolean variable to false so that SelectionChanged event will be fired when actually selection Changes in the ComboBox.
Try This:
bool loadevent = false;
private void Bill_Load(object sender, EventArgs e)
{
loadevent = true;
con = new SqlConnection(constring);
cmd = new SqlCommand("select billid from bill", con);
adapter = new SqlDataAdapter(cmd);
ds = new DataSet();
adapter.Fill(ds);
dt = ds.Tables[0];
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "billid";
comboBox1.ValueMember = "billid";
MessageBox.Show(id.ToString());
loadevent = false;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (!loadevent)
{
MessageBox.Show(comboBox1.Text);
int id;
id = Convert.ToInt32(comboBox1.Text);
con = new SqlConnection(constring);
cmd = new SqlCommand("select * from bill where billid=#id", con);
// cmd.Parameters.Add("#id", Convert.ToInt32(comboBox1.Text));
cmd.Parameters.Add("#id", id);
adapter = new SqlDataAdapter(cmd);
ds = new DataSet();
adapter.Fill(ds);
dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
textBox1.Text = dr[1].ToString();
textBox2.Text = dr[2].ToString();
textBox3.Text = dr[4].ToString();
textBox4.Text = dr[3].ToString();
textBox5.Text = dr[5].ToString();
textBox6.Text = dr[6].ToString();
textBox7.Text = dr[7].ToString();
textBox8.Text = dr[8].ToString();
textBox9.Text = dr[9].ToString();
textBox10.Text = dr[10].ToString();
}
}
}

Textbox value will show other textbox information without clicking button

this code is working good. But i want to search data without click button. when i will write Employee name if it will exists in table it will show my information otherwise i will insert data. Please help me...
protected void btnSubmit_Click(object sender, EventArgs e){
var sqlQuery = "SELECT EmployeeID, Weight, Amount FROM Supplier where EmployeeName= '" + TextBox2.Text+ "'";
//Create Instance for DataSet
var DS = new DataSet();
//Create Instance for SqlConnection
var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["inventoryConnectionString"].ConnectionString);
//Create Instance for SqlCommand
var cmd = new SqlCommand(sqlQuery, conn);
var DA = new SqlDataAdapter(cmd);
DS.Clear();
try{
DA.Fill(DS);
}
catch (Exception ex){}
foreach (DataRow row in DS.Tables[0].Rows){
txtBoxId.Text = row["EmployeeID"].ToString();
txtboxw.Text = row["Weight"].ToString();
txtboxam.Text = row["Amount"].ToString();
}
}
You could use TextChanged event handler and a parameterized query for sql injection protection. However, the code below be forwarned is costly because it has to access the Database from time to time.
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
String connString = ConfigurationManager.ConnectionStrings["inventoryConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(connString))
{
con.Open();
String strSQL = "SELECT EmployeeID, Weight, Amount FROM Supplier where EmployeeName=#EmployeeName";
using (SqlCommand cmd = new SqlCommand(strSQL, con))
{
cmd.Parameters.Add("#EmployeeName", SqlDbType.VarChar).Value = TextBox2.Text;
using (SqlDataAdapter DA = new SqlDataAdapter(cmd))
{
DA.SelectCommand = cmd;
try
{
DataSet DS = new DataSet();
DA.Fill(DS);
foreach (DataRow row in DS.Tables[0].Rows)
{
txtBoxId.Text = row["EmployeeID"].ToString();
txtboxw.Text = row["Weight"].ToString();
txtboxam.Text = row["Amount"].ToString();
}
}
catch (Exception ex)
{
}
}
}
}
}
However, you could probably just cached the whole table and then from there do the query instead of going to the database from time to time like:
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
var query = from myRow in myDataTable.AsEnumerable()
where r.Field<string>("EmployeeName")==TextBox2.Text
select new
{
EmployeeID = myRow.Field<int>("EmployeeID"),
Weight = contact.Field<int>("Weight"),
Amount = order.Field<double>("Amount")
};
foreach (var row in query)
{
txtBoxId.Text = row.Employee.ToString();
txtboxw.Text = row.Weight.ToString();
txtboxam.Text = row.Amount.ToString();
}
}
I've got a different approach. Assuming the contents of your Supplier table do not change frequently, I'd suggest caching the contents of that table on page load and then just reference that table when the text in that text box is changed.
private DataTable _suppliers;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sqlQuery = "SELECT EmployeeID, Weight, Amount, EmployeeName FROM Supplier";
var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["inventoryConnectionString"].ConnectionString);
_suppliers = new DataTable();
var cmd = new SqlCommand(sqlQuery, conn);
conn.Open();
var SDA = new SqlDataAdapter(cmd);
SDA.Fill(_suppliers);
}
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
DataView DV = new DataView(_suppliers);
DV.RowFilter = string.Format("EmployeeName LIKE '%{0}%'", TextBox2.Text);
if (DV.Count == 1)
{
var row = DV[0];
txtBoxId.Text = row["EmployeeID"].ToString();
txtboxw.Text = row["Weight"].ToString();
txtboxam.Text = row["Amount"].ToString();
}
}
Additionally, you may want to look into using an updatepanel to handle the text changed event asynchronously instead of using the TextChanged event.

Categories

Resources