首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不能为mysql应用自动增量

问我不能为mysql应用自动增量
EN

Stack Overflow用户
提问于 2014-04-22 12:00:31
回答 2查看 60关注 0票数 0

“插入Fn_Registration值(‘+ 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 +’,+‘’+ txtAC2.Text +‘,’+‘+ txtIFSC2.Text +’‘,“+”+txtIFSC2.Text+’‘;

这是我在mysql数据库中插入的代码,其中id num必须是自动递增的,但是mysql不执行自动增量可以帮助任何人.

C#代码

代码语言:javascript
复制
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();
EN

回答 2

Stack Overflow用户

发布于 2014-04-22 12:07:56

在插入查询中,可以使用:

代码语言:javascript
复制
INSERT INTO Fn_Registration(Names,of,columns,that,you,want,to,give,a,value) VALUES(values,for,those,columns);

如果从要给值的列的名称中排除id列,则SQL应自动增加值。

票数 1
EN

Stack Overflow用户

发布于 2014-04-22 12:08:03

可以通过修改表使MySQL自动递增,如下所示:

代码语言:javascript
复制
ALTER TABLE tablename MODIFY id_Column INT NOT NULL AUTO_INCREMENT;

MySQL文档

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23218905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档