Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# form Window
UGIcon.Open();
                    cmd = new SqlCommand("update admin set name='" + textBox5.Text + "', age='" + numericUpDown1.Value.ToString() + "', phone='" + numericUpDown2.Value.ToString() + "', question='" + comboBox1.SelectedItem.ToString()+"', answer='" + textBox4.Text + "')", UGIcon);
                    
                       SqlDataReader sd;
                    sd = cmd.ExecuteReader(); i m getting error here 
 
                    MessageBox.Show("Thank You!!! Your Details updated", "Updation Window", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    groupBox1.Visible = false;
                    UGIcon.Close();
Posted 10-Dec-12 0:34am
Comments
Krunal Rohit at 10-Dec-12 5:38am
   
What is your condition ?? I'm talink about where clause and why do you need to close the brace in query ???
selva_1990 at 10-Dec-12 5:42am
   
i need to update entire table so i didnt use where condition
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

mylib.cmd = new SqlCommand("Update BUHeadMstr set Eid =@Eid, Bid=@Bid,CorpId=@CorpId,CreatedBy=@UId,CreatedOn=@Date where Buheadid =@buheadId    ", mylib.objDBConn);
            mylib.cmd.CommandType = CommandType.Text;
mylib.cmd.Parameters.AddWithValue("@Eid", objAdmin.Eid);
int i = mylib.cmd.ExecuteNonQuery();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Please use paramterised queries when writing inline SQL such as yours, below is an example of how to do this.
 
C# SqlParameter Example[^]
 
using this approach reduces / removes the chance of SQL Injection (decribed in the following article)
 
How do Parameterised queries help against SQL Injection[^]
 
This code project article highlights the ways to insert, update and delete data from a database using ADO.NET. As you can see when you read it. It uses the executeNonQuery as this returns the number of rows that have been effected by your query.
 
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
  Permalink  
Comments
__TR__ at 10-Dec-12 6:27am
   
My 5!
Simon_Whale at 10-Dec-12 6:28am
   
Thanks __TR__
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

why to close the ')' in front of UGIcon(connection),remove the )...
and try this
 
cmd = new SqlCommand("update admin set name='" + textBox5.Text + "', age='" + numericUpDown1.Value.ToString() + "', phone='" + numericUpDown2.Value.ToString() + "', question='" + comboBox1.SelectedItem.ToString()+"',
answer='" + textBox4.Text + "'", UGIcon) and Give Where Clause...
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use it,
UGIcon.Open();
                    cmd = new SqlCommand("update admin set name='" + textBox5.Text + "', age='" + numericUpDown1.Value.ToString() + "', phone='" + numericUpDown2.Value.ToString() + "', question='" + comboBox1.SelectedItem.ToString()+"', answer='" + textBox4.Text + "'    ", UGIcon); // error is at line wich is highlight by underscore at that place you have use closing bracket which cause error
                    
                       SqlDataReader sd;
                    sd = cmd.ExecuteReader(); i m getting error here 
 
                    MessageBox.Show("Thank You!!! Your Details updated", "Updation Window", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    groupBox1.Visible = false;
                    UGIcon.Close();
Happy Coding!
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think your code should look like this:
UGIcon.Open();
cmd = new SqlCommand("update admin set name='" + textBox5.Text + "', age='" + numericUpDown1.Value.ToString() + "', phone='" + numericUpDown2.Value.ToString() + "', question='" + comboBox1.SelectedItem.ToString()+"', answer='" + textBox4.Text + "'", UGIcon);
                    
SqlDataReader sd;
sd = cmd.ExecuteReader(); 
 
MessageBox.Show("Thank You!!! Your Details updated", "Updation Window", MessageBoxButtons.OK, MessageBoxIcon.Information);
groupBox1.Visible = false;
UGIcon.Close();
 
There is an unnecessary parenthesis after textbox4.Text.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Why u r using ExecuteReader() instead of use cmd.ExecuteNonQuery() method.
  Permalink  
v2
Comments
Krunal Rohit at 10-Dec-12 5:40am
   
post it as comment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100