Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
     protected void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {   SqlConnection mysqlconection = new SqlConnection(myconect);
                SqlDataAdapter myadp = new SqlDataAdapter();
                myadp.UpdateCommand = new SqlCommand("Update [tbl_CustInfo] Set [mydate]=@mydate,[name]=@name,[idnasb]=@idnasb,[iddevice]=@iddevice,[email]=@email,[mobile]=@mobile,[tel]=@tel,[Adress]=@Adress WHERE [codemeli]=" + txtcodemeli.Text, mysqlconection);
                mydat = dryear.SelectedItem.Value.ToString() + "/" + drmonth.SelectedItem.Value.ToString() + "/" + drday.SelectedItem.Value.ToString();
                myadp.UpdateCommand.Parameters.Add("@mydate", SqlDbType.NVarChar, 15).Value = mydat;
                myadp.UpdateCommand.Parameters.Add("@name", SqlDbType.NVarChar, 100).Value = txtname.Text;
                myadp.UpdateCommand.Parameters.Add("@idnasb", SqlDbType.Int).Value = dridnasb.SelectedIndex;
                myadp.UpdateCommand.Parameters.Add("@iddevice", SqlDbType.Int).Value = drdevice.SelectedIndex;
                myadp.UpdateCommand.Parameters.Add("@email", SqlDbType.NVarChar, 50).Value = txtemail.Text.ToString();
                myadp.UpdateCommand.Parameters.Add("@mobile", SqlDbType.NVarChar, 11).Value = txtmobile.Text.ToString();
                myadp.UpdateCommand.Parameters.Add("@tel", SqlDbType.NVarChar, 11).Value = txttel.Text.ToString();
                myadp.UpdateCommand.Parameters.Add("@adress", SqlDbType.NVarChar, 250).Value = txtAdress.Text;
                myadp.UpdateCommand.Connection = mysqlconection;
                mysqlconection.Open();
                myadp.UpdateCommand.ExecuteNonQuery();
                mysqlconection.Close();                
            }
            catch (Exception ex)
            {
                errorLabel.Text = ex.Message;
                errorLabel.Visible = true;
            }
        }

What I have tried:

// when click edit Button i see above error message
// can you  tell me what is problem
Posted
Updated 26-Nov-16 7:57am
Comments
moj1978 26-Nov-16 11:52am    
i have a id that is primary key
and one field "codemeli" that it is not primary key but it is Unique
i search in this table with field "codemeli"
is it true?
Philippe Mori 28-Nov-16 9:42am    
What is the column definition of codemeli in the database? And as suggested by someone, use parametrised query parameter for that parameter too.

1 solution

Well... that's because an int is a signed 32-bit value with a range of -2,147,483,648 to 2,147,483,647. Values outside that range cannot be held in a int.
Use an unsigned integer or uint (0 to 4,294,967,295), or consider changing to a long (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)

And do yourself a favour: you clearly know about parameterised queries and SQL Injection, so why use string concatenation as well? Even the one instance you have in your code leaves you wide open to having your database damaged or destroyed...
 
Share this answer
 
v2
Comments
moj1978 26-Nov-16 11:45am    
you can see this two item is int and fill with droppdownlist.SelectedIndex
this program don't need integer or uint
-----------------------------------------------------------
myadp.UpdateCommand.Parameters.Add("@idnasb", SqlDbType.Int).Value = dridnasb.SelectedIndex;
myadp.UpdateCommand.Parameters.Add("@iddevice", SqlDbType.Int).Value = drdevice.SelectedIndex;
----------------------------------------------------
can you help me?
OriginalGriff 26-Nov-16 11:51am    
Your error message is very explicit: you are passing a string value to SQL which it is trying to convert to an integer value. That string contains "339159654" which exceeds the value you can fit into an integer, so SQL complains.
Which value? Don't know - that's up to you and your data.
But...if it's a SelectedIndex I'd be amazed: you would need a drop down list or similar control with over 3,000,000,000 items in it - which would be patently ludicrous.
Use the debugger, look at your data. We can't!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900