user3531533
user3531533

Reputation: 65

I can't apply auto increment for mysql

"INSERT INTO Fn_Registration VALUES ( '"+ txtFirstName.Text + "', '" + txtLastName.Text + "', " + " '" + txtEmailId.Text + "', " + " '" + txtPassword.Text + "', " + " '" + txtPanNumber.Text + "', " + " '" + txtAddress1.Text + "', " + " '" + txtAddress2.Text + "', " + " '" + txtFaxNo.Text + "'," + " '" + txtFirmName.Text + "', " + " '" + txtPhoneNumber.Text + "', " + " '" + txtTinNumber.Text + "','" + txtAccountsStart.Text + "','" + txtAccountsEnd.Text + "','" + cbbVat.Text + "', " + " '" + cbbstates.Text + "', " + " '" + txtCity.Text + "', '" + txtBankName.Text + "', '" + txtAccountNumber.Text + "', " + " '" + txtIFSCCode.Text + "', " + " '" + txtBN1.Text + "', " + " '" + txtAC1.Text + "', " + " '" + txtIFSC1.Text + "', " + " '" + txtBN2.Text + "', " + " '" + txtAC2.Text + "', " + " '" + txtIFSC2.Text + "')";

this is my insert code into mysql database where id num must be auto increamented,,, but mysql doesnot performs auto incrementation can any one help .........

C# code

string regInset = "INSERT INTO Fn_Registration VALUES ('" + 101 + "', '"+ 
txtFirstName.Text + "', '" + txtLastName.Text + "', " + " '" + txtEmailId.Text +
 "', " + " '" + txtPassword.Text + "', " + " '" + txtPanNumber.Text + "', " + " '" + 
txtAddress1.Text + "', " + " '" + txtAddress2.Text + "', " + " '" + txtFaxNo.Text +
 "'," + " '" + txtFirmName.Text + "', " + " '" + txtPhoneNumber.Text + "', " + " '" 
+ txtTinNumber.Text + "','" + txtAccountsStart.Text + "','" + txtAccountsEnd.Text + 
"','" + cbbVat.Text + "', " + " '" + cbbstates.Text + "', " + " '" + txtCity.Text +
 "', '" + txtBankName.Text + "', '" + txtAccountNumber.Text + "', " + " '" + 
txtIFSCCode.Text + "', " + " '" + txtBN1.Text + "', " + " '" + txtAC1.Text + "', " + 

" '" + txtIFSC1.Text + "', " + " '" + txtBN2.Text + "', " + " '" + txtAC2.Text + "', " 
+ " '" + txtIFSC2.Text + "')";

cmd = new MySqlCommand(regInset, con);
da = new MySqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "Fn_Registration");
this.clearData();

Upvotes: 0

Views: 70

Answers (2)

Psychemaster
Psychemaster

Reputation: 876

MySQL can be made to auto increment on a table by modifying that table as follows:

ALTER TABLE tablename MODIFY id_Column INT NOT NULL AUTO_INCREMENT;

MySQL Documentation

Upvotes: 0

Bob Brinks
Bob Brinks

Reputation: 1392

In your insert query you can use:

INSERT INTO Fn_Registration(Names,of,columns,that,you,want,to,give,a,value) VALUES(values,for,those,columns);

If you then exclude the id column from the names of columns you want to give a value, SQL should automatically increment the value.

Upvotes: 1

Related Questions