Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL
error is giving at cmd.ExecuteNonQuery();
 

 

 
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
 
        int userid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());
        //ring user = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();

        string username = gvDetails.DataKeys[e.RowIndex].Values["U_name"].ToString();
        //string imagename = gvDetails.DataKeys[e.RowIndex].Values["ImageName"].ToString();

        TextBox txtU_Email = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtU_Email");
        TextBox txtImageName = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtImageName");
        TextBox txtDescription = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtDescription");
        TextBox txtCategoryName = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtCategoryName");
 
        TextBox txtADshop_name = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_name");
        TextBox txtADShop_Address = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADShop_Address");
        TextBox txtADshop_city = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_city");
        TextBox txtADshop_mob = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_mob");
        TextBox txtADshop_Email = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtADshop_Email");
        TextBox txtAreaName = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtAreaName");
        TextBox txtstartddate = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtstartddate");
        TextBox txtendddate = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtendddate");
        TextBox txtImagePath = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtImagePath");
        TextBox txtdiffrence = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtdiffrence");
        con.Open();
        
        
        OleDbCommand cmd = new OleDbCommand("UPDATE LOGIN u ,SlideShowTable s SET u.U_Email = '" + txtU_Email.Text + "',s.ImageName='" + txtImageName.Text + "',s.Description='" + txtDescription.Text + "',s.CategoryName='" + txtCategoryName.Text + "',s.ADshop_name='" + txtADshop_name.Text + "',s.ADShop_Address='" + txtADShop_Address.Text + "',s.ADshop_city='" + txtADshop_city.Text + "',s.ADshop_mob='" + txtADshop_mob.Text + "',s.ADshop_Email='" + txtADshop_Email.Text + "',s.AreaName='" + txtAreaName.Text + "',s.startddate='" + txtstartddate.Text + "',s.endddate='" + txtendddate.Text + "',s.ImagePath='" + txtImagePath.Text + "',s.diffrence='" + txtdiffrence.Text + "' where s.U_id=" + userid + " and u.U_id= " + userid, con);
 

 
        cmd.ExecuteNonQuery();
        con.Close();
        lblresult.ForeColor = Color.Green;
        lblresult.Text = username + " Details Updated successfully";
        gvDetails.EditIndex = -1;
        BindEmployeeDetails();
    }
Posted 17-Apr-13 23:15pm
Edited 17-Apr-13 23:16pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
What is the data type used in database for mobile,start date and end date columns, may be bcoz those columns it is giving error. check once...
  Permalink  
Comments
Amirsalgar1 at 18-Apr-13 4:40am
   
memo for start and end date
and number for mobile
Member61 at 18-Apr-13 4:51am
   
then convert the mobile textbox value to integer
Amirsalgar1 at 18-Apr-13 4:53am
   
sir ,
i tried by changing data type integer to memo but still it gives me the same error
Member61 at 18-Apr-13 4:56am
   
And What about userid data type?
Amirsalgar1 at 18-Apr-13 4:56am
   
autonumber
Amirsalgar1 at 18-Apr-13 4:57am
   
sorry its an integer
Amirsalgar1 at 18-Apr-13 4:58am
   
and U_id = auto number
Member61 at 18-Apr-13 4:58am
   
Put break point near executereader, run and enter input ,get that query along with column values and paste here ..
Member61 at 18-Apr-13 4:59am
   
And provide ur database structure also...
Amirsalgar1 at 18-Apr-13 5:01am
   
i dont know how :(
Amirsalgar1 at 18-Apr-13 5:02am
   
if possible will you please join me on team viewer?
Member61 at 18-Apr-13 5:07am
   
Give me ur database structure?
Member61 at 18-Apr-13 5:08am
   
Check data type of userid in both the table Login and Slideshowtable same or different?
Amirsalgar1 at 18-Apr-13 5:08am
   
175 735 453
3069
Amirsalgar1 at 18-Apr-13 5:10am
   
it is so big sir ok m typing
Member61 at 18-Apr-13 5:13am
   
What is this? In both tables same data type?
Amirsalgar1 at 18-Apr-13 5:16am
   
there is a U_id in both database with data type autonumber in login and number in slideshow
Amirsalgar1 at 18-Apr-13 5:11am
   
sir please join me on team viewer
Member61 at 18-Apr-13 5:13am
   
And dont give ur team viewer any one...
Amirsalgar1 at 18-Apr-13 5:17am
   
sorry sir but database is so big should i mail u that database?
Member61 at 18-Apr-13 5:27am
   
First tell me, have u tried solution 3?
Member61 at 18-Apr-13 5:19am
   
Check my solution...
Member61 at 18-Apr-13 5:20am
   
and try to do like that...
Member61 at 18-Apr-13 5:24am
   
Have u tried solution3?
Amirsalgar1 at 18-Apr-13 5:32am
   
sir , there is in update query ...where s.U_id=" + userid + " and u.U_id= " + userid, con); is it correct expression for integer?
Amirsalgar1 at 18-Apr-13 5:32am
   
is it correct syntax?
Amirsalgar1 at 18-Apr-13 5:27am
   
checking :(
Member61 at 18-Apr-13 5:38am
   
Yes, if userid variable is int.
Amirsalgar1 at 18-Apr-13 6:30am
   
okay
Amirsalgar1 at 18-Apr-13 6:58am
   
still not working
Member61 at 18-Apr-13 6:33am
   
is ur problem solved?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You should use parameteriazed queries instead, as the current on is wonerable to SQL injection attacs, plese see this:
How to avoid SQL Injection[^]
 
They are also easier to debug Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hi,
 
Check below link...
 
http://support.microsoft.com/kb/175258[^]
  Permalink  

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

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 18 Apr 2013
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