Click here to Skip to main content
11,923,046 members (62,748 online)
Rate this:
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");
        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);

        lblresult.ForeColor = Color.Green;
        lblresult.Text = username + " Details Updated successfully";
        gvDetails.EditIndex = -1;
Posted 17-Apr-13 23:15pm
Edited 17-Apr-13 23:16pm
Joezer BH38.4K
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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...
Amirsalgar1 18-Apr-13 4:40am
memo for start and end date
and number for mobile
Member61 18-Apr-13 4:51am
then convert the mobile textbox value to integer
Amirsalgar1 18-Apr-13 4:53am
sir ,
i tried by changing data type integer to memo but still it gives me the same error
Member61 18-Apr-13 4:56am
And What about userid data type?
Amirsalgar1 18-Apr-13 4:56am
Amirsalgar1 18-Apr-13 4:57am
sorry its an integer
Amirsalgar1 18-Apr-13 4:58am
and U_id = auto number
Member61 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 18-Apr-13 4:59am
And provide ur database structure also...
Amirsalgar1 18-Apr-13 5:01am
i dont know how :(
Amirsalgar1 18-Apr-13 5:02am
if possible will you please join me on team viewer?
Member61 18-Apr-13 5:07am
Give me ur database structure?
Member61 18-Apr-13 5:08am
Check data type of userid in both the table Login and Slideshowtable same or different?
Amirsalgar1 18-Apr-13 5:08am
175 735 453
Amirsalgar1 18-Apr-13 5:10am
it is so big sir ok m typing
Member61 18-Apr-13 5:13am
What is this? In both tables same data type?
Amirsalgar1 18-Apr-13 5:16am
there is a U_id in both database with data type autonumber in login and number in slideshow
Amirsalgar1 18-Apr-13 5:11am
sir please join me on team viewer
Member61 18-Apr-13 5:13am
And dont give ur team viewer any one...
Amirsalgar1 18-Apr-13 5:17am
sorry sir but database is so big should i mail u that database?
Member61 18-Apr-13 5:27am
First tell me, have u tried solution 3?
Member61 18-Apr-13 5:19am
Check my solution...
Member61 18-Apr-13 5:20am
and try to do like that...
Member61 18-Apr-13 5:24am
Have u tried solution3?
Amirsalgar1 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 18-Apr-13 5:32am
is it correct syntax?
Amirsalgar1 18-Apr-13 5:27am
checking :(
Member61 18-Apr-13 5:38am
Yes, if userid variable is int.
Amirsalgar1 18-Apr-13 6:30am
Amirsalgar1 18-Apr-13 6:58am
still not working
Member61 18-Apr-13 6:33am
is ur problem solved?
Rate this: bad
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 | :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


Check below link...[^]

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
Web01 | 2.8.151125.3 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2015
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