943,688 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 2780
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 17th, 2009
0

Update from Asp.net to Sql server db

Expand Post »
...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

CodeAsp.net C#---Sql server db)


c# Syntax (Toggle Plain Text)
  1. private void btedit_Click(object sender, System.EventArgs e)
  2. {
  3. LabErr.Text="";
  4. if(Page.IsValid==true)
  5. {
  6. SqlConnection con1=new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=newbie");
  7. con1.Open();
  8. SqlCommand cmd=new SqlCommand("Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')",con1);
  9. cmd.ExecuteNonQuery();
  10. }
  11. else
  12. {
  13. //txtrnme.Text="";
  14. LabErr.Text="Please try Again";
  15. }


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

ICHU
Last edited by peter_budo; Jun 19th, 2009 at 4:22 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikichu is offline Offline
14 posts
since Jun 2009
Jun 17th, 2009
0

Re: Update from Asp.net to Sql server db

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.

c# Syntax (Toggle Plain Text)
  1. private void btedit_Click(object sender, System.EventArgs e)
  2. {
  3. LabErr.Text=string.Empty;
  4. if(Page.IsValid)
  5. {
  6. using (SqlConnection con1=new SqlConnection(@"Server=sqloledb.1;User ID=sa;password=;Data Source=IRID_BDC1;Initial Catalog=newbie"))
  7. {
  8. con1.Open();
  9. string query = "Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')";
  10. if (string.IsNullOrEmpty(Droploc.SelectedItem.Text))
  11. throw new Exception();
  12. int iTest = Convert.ToInt32(Droploc.SelectedItem.Text);
  13. using (SqlCommand cmd=new SqlCommand(query,con1))
  14. {
  15. cmd.ExecuteNonQuery();
  16. }
  17. con1.Close();
  18. }
  19. }
  20. else
  21. {
  22. //txtrnme.Text="";
  23. LabErr.Text="Please try Again";
  24. }
  25. }

Try something like that and see if you get an exception. That should get you pointed in the right direction.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jun 18th, 2009
0

Re: Update from Asp.net to Sql server db

try debugging the code.perhaps the empty values are passed in the query
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007
Jun 22nd, 2009
0

Re: Update from Asp.net to Sql server db

..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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikichu is offline Offline
14 posts
since Jun 2009
Jun 22nd, 2009
0

Re: Update from Asp.net to Sql server db

add a watch in the values at this point
ASP.NET Syntax (Toggle Plain Text)
  1. SqlCommand cmd=new SqlCommand("Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')",con1);
Reputation Points: 10
Solved Threads: 12
Posting Whiz in Training
carobee is offline Offline
209 posts
since Dec 2007
Jun 23rd, 2009
0

Re: Update from Asp.net to Sql server db

Could you please post the table structure of Loc_mast?
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009
Jun 24th, 2009
0

Re: Update from Asp.net to Sql server db

Click to Expand / Collapse  Quote originally posted by mail2saion ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikichu is offline Offline
14 posts
since Jun 2009
Jun 24th, 2009
0

Re: Update from Asp.net to Sql server db

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.
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009
Jun 24th, 2009
0

Re: Update from Asp.net to Sql server db

Click to Expand / Collapse  Quote originally posted by mail2saion ...
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"

Reputation Points: 10
Solved Threads: 0
Newbie Poster
nikichu is offline Offline
14 posts
since Jun 2009
Jun 24th, 2009
0

Re: Update from Asp.net to Sql server db

Please post your bind code & the qurey that you use to update.
Reputation Points: 26
Solved Threads: 44
Posting Whiz in Training
mail2saion is offline Offline
247 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC