...hope some body can help me resolve the problem....where i have to update a particular data ,
the datas are retreived from the db using a dropdownlist,selected data are updated inside a textbox...........
.....where there are constraints set by validators
for space and !^#$%&*^----charaecters:

My problm is data is not updated,please help me

Code:(Asp.net C#---Sql server db)

private void btedit_Click(object sender, System.EventArgs e)
		{
			LabErr.Text="";
			if(Page.IsValid==true)
			{
				SqlConnection con1=new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=newbie");
				con1.Open();
				SqlCommand cmd=new SqlCommand("Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')",con1);
				cmd.ExecuteNonQuery();
			}
			else
			{
			//txtrnme.Text="";
             LabErr.Text="Please try Again";
			}

..please suggest a soln..........

ICHU

Recommended Answers

All 12 Replies

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.

try debugging the code.perhaps the empty values are passed in the query

:'( ..Still not working

.....Im using 2 radio buttons one to add and nther to edit

if i switch from one button to another,the datas are not gettng inserted to sql db

......the same the case as edit....
errors still........

ICHU

add a watch in the values at this point

SqlCommand cmd=new SqlCommand("Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')",con1);

Could you please post the table structure of Loc_mast?

Could you please post the table structure of Loc_mast?

structure of Loc_mast(SQL SERVER)

Colname Datatype length
Slno int 4(generated automatically-(*identity)
Loc_no nvarchar 50

ICHU

Use Slno for update operation rather than loc_no. Where clause shoud be Where Slno =('"+ Droploc.SelectedItem.Value+"')",con1) When you bind text properties of dropdown list must bind also Value properties by Slno.

Use Slno for update operation rather than loc_no. Where clause shoud be Where Slno =('"+ Droploc.SelectedItem.Value+"')",con1) When you bind text properties of dropdown list must bind also Value properties by Slno.

"...updates only the first record in db"

:(

Please post your bind code & the qurey that you use to update.

Please post your bind code & the qurey that you use to update.

Bind:

SqlConnection con1=new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=Nisha");
con1.Open();
  SqlCommand cmmd=new SqlCommand("Select * from  Loc_mast",con1);
 SqlDataReader dar=cmmd.ExecuteReader();
  Droploc.Items.Clear(); 
  Droploc.DataSource=dar;
  Droploc.DataTextField ="Loc";
 Droploc.DataValueField="Slno";
 Droploc.DataBind();
 con1.Close();

Update

RadioButton1.Checked =false;
if(Page.IsValid == true) 
{  
using (SqlConnection con1=new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=Nisha"))
{    
con1.Open();  
SqlCommand cmd=new SqlCommand("Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Slno =('"+ Droploc.SelectedItem.Value+"')",con1);   
cmd.ExecuteNonQuery();  
con1.Close();  
}}

Please post your bind code & the qurey that you use to update.

The ASP.NET Application Service APIs are designed to be pluggable and implementation agnostic, which means that the APIs do not hardcode the details of where data is stored with them. Instead, the APIs call into “providers”,you can get lot of information about the Software Testing from Macrotesting . Any of you guys get useful information about this please share wih me.

All the best for your carrer..
Meganathan

hello someone thre to help please............
still stuck in the code,which updates only the first record!!!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.