Click here to Skip to main content
14,869,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo every one im trying to insert a new User_Name into a table using mysql but I keep getting error That company Name already exsits below is my insert statement
MySqlCommand sqlcom = new MySqlCommand("Insert Into t_users(Company_Name, User_Name,Serial_Number,Full_Name,Password,Cell_Number,Email,User_Type,Active,
Keywords,Signature)VALUE(@Company_Name,@User_Name,@Serial_Number,@Full_Name,@Password,@Cell_Number,@Email,@User_Type,@Active,@Keyword,@Signature)
SQL
sqlcom.Parameters.Add("@Company_Name", MySqlDbType.VarChar, 100).Value =CompanyName;
            sqlcom.Parameters.Add("@User_Name", MySqlDbType.VarChar, 100).Value = txtInsertUser.Text;

            sqlcom.Parameters.Add("@Serial_Number", MySqlDbType.VarChar, 100).Value = txtInsertSerial.Text;


            sqlcom.Parameters.Add("@Full_Name", MySqlDbType.VarChar, 100).Value = txtInsertFullName.Text;
            sqlcom.Parameters.Add("@Password", MySqlDbType.VarChar, 100).Value = txtInsertPassword.Text;
                sqlcom.Parameters.Add("@Cell_Number", MySqlDbType.VarChar, 100).Value = txtInsertCell.Text;
                sqlcom.Parameters.Add("@Email", MySqlDbType.VarChar, 100).Value = txtInsertEmail.Text;

sqlcom.Parameters.Add("@User_Type", MySqlDbType.Bit).Value = chkUsertypeInsert.Checked;
sqlcom.Parameters.Add("@Active", MySqlDbType.Bit).Value = chkInsertActive.Checked;
sqlcom.Parameters.Add("@Keyword", MySqlDbType.VarChar, 100).Value = txtInsertKeyword.Text;
sqlcom.Parameters.Add("@Signature", MySqlDbType.VarChar, 100).Value = txtInsertSignature.Text;


sqlcom.ExecuteNonQuery();
MySqlDataAdapter da = new MySqlDataAdapter("select * from T_company", mycon2);

DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = new DataTable();
da.Fill(dt);

gdvauthors.DataSource = dt;
gdvauthors.DataBind();


my table
has the following columns

Company name PK
User_name pk
Serial_number
Full_Name
Password
Cell_Number
Email
User_type
Active
Keywords
Signature
Posted

1 solution

use ON DULPLICATE UPDATE ccolname=value(colname)
   

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