Change your query to be set to a string and break the debugger in there. Your drop down list might have an empty string value which would cause the update to not work. You are also not closing your SQL connection and you will run the connection pool out of available connections if your site has many users.
private void btedit_Click(object sender, System.EventArgs e)
{
LabErr.Text=string.Empty;
if(Page.IsValid)
{
using (SqlConnection con1=new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=newbie"))
{
con1.Open();
string query = "Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')";
if (string.IsNullOrEmpty(Droploc.SelectedItem.Text))
throw new Exception();
int iTest = Convert.ToInt32(Droploc.SelectedItem.Text);
using (SqlCommand cmd=new SqlCommand(query,con1))
{
cmd.ExecuteNonQuery();
}
con1.Close();
}
}
else
{
//txtrnme.Text="";
LabErr.Text="Please try Again";
}
}
Try something like that and see if you get an exception. That should get you pointed in the right direction.
Reputation Points: 1749
Solved Threads: 735
Senior Poster
Offline 3,948 posts
since Feb 2009