“插入Fn_Registration VALUES('”+ txtFirstName.Text +“','”+ txtLastName.Text +“',”+“'”+ txtEmailId.Text +“',”+“'”+ txtPassword。文字+“',”+“'”+ 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 +”')“;
这是我的插入代码进入mysql数据库,其中id num必须是自动递增的,但是mysql不执行自动递增可以任何一个帮助.........
C#代码
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();
答案 0 :(得分:1)
在插入查询中,您可以使用:
INSERT INTO Fn_Registration(Names,of,columns,that,you,want,to,give,a,value) VALUES(values,for,those,columns);
如果然后从要为其赋值的列的名称中排除id列,则SQL应自动增加该值。
答案 1 :(得分:0)
通过修改该表,可以使MySQL在表上自动递增:
ALTER TABLE tablename MODIFY id_Column INT NOT NULL AUTO_INCREMENT;