Update from Asp.net to Sql server db

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 14
Reputation: nikichu is an unknown quantity at this point 
Solved Threads: 0
nikichu nikichu is offline Offline
Newbie Poster

Update from Asp.net to Sql server db

 
0
  #1
Jun 17th, 2009
...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)


  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,210
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 572
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: Update from Asp.net to Sql server db

 
0
  #2
Jun 17th, 2009
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.

  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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: Update from Asp.net to Sql server db

 
0
  #3
Jun 18th, 2009
try debugging the code.perhaps the empty values are passed in the query
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: nikichu is an unknown quantity at this point 
Solved Threads: 0
nikichu nikichu is offline Offline
Newbie Poster

Re: Update from Asp.net to Sql server db

 
0
  #4
Jun 22nd, 2009
..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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 205
Reputation: carobee is an unknown quantity at this point 
Solved Threads: 11
carobee carobee is offline Offline
Posting Whiz in Training

Re: Update from Asp.net to Sql server db

 
0
  #5
Jun 22nd, 2009
add a watch in the values at this point
  1. SqlCommand cmd=new SqlCommand("Update Loc_mast Set Loc =('"+ txtrnme.Text+"') Where Loc =('"+ Droploc.SelectedItem.Text+"')",con1);
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 217
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 31
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: Update from Asp.net to Sql server db

 
0
  #6
Jun 23rd, 2009
Could you please post the table structure of Loc_mast?
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: nikichu is an unknown quantity at this point 
Solved Threads: 0
nikichu nikichu is offline Offline
Newbie Poster

Re: Update from Asp.net to Sql server db

 
0
  #7
Jun 24th, 2009
Originally Posted by mail2saion View Post
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 217
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 31
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: Update from Asp.net to Sql server db

 
0
  #8
Jun 24th, 2009
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.
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: nikichu is an unknown quantity at this point 
Solved Threads: 0
nikichu nikichu is offline Offline
Newbie Poster

Re: Update from Asp.net to Sql server db

 
0
  #9
Jun 24th, 2009
Originally Posted by mail2saion View Post
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"

Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 217
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 31
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: Update from Asp.net to Sql server db

 
0
  #10
Jun 24th, 2009
Please post your bind code & the qurey that you use to update.
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC