Click here to Skip to main content
12,449,910 members (42,264 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# form
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 9-Dec-12 23:34pm
Comments
Krunal Rohit 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 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__ 10-Dec-12 6:27am
   
My 5!
Simon_Whale 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 10-Dec-12 5:40am
   
post it as comment
Member 11388228 20-Jan-15 7:04am
   
how to solve this problem
i will write this coding
string strQuery = "insert into Purchase values('"+dateTimepurchasedate.Text+"','"+cBoxbrandnamepurchase.Text+"','"+cBoxproductnamepurchase.Text+"','"+txtMRPpurchase.Text+"',"+txtquntypurchase.Text+","+txtpurchaseprice.Text+","+txtvat.Text+","+txttotal.Text+","+txtdiscount.Text+",'"+result+"',"+txtnettotal.Text+",'"+cBoxsuppliername.Text+"')"

it will show error in incorrect syntax error how to solve this

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2016
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