2014-04-24 17 views
0

我我用下面的语句如何在mysql中执行自动增量?

string regInset = 
    "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 + "', " + " '"+txtFinancialYearStart.Text+"','"+ 
    txtFinancialYearEnd.Text+"','" + txtAccountsStart.Text + "', " + " '" + 
    txtAccountsEnd.Text + "','" + cbbVat.Text + "', " + " '" + 
    cbbstates.Text + "', " + " '" + txtCity.Text +"','"+ 
    txtCircle.Text+"','"+txtDivision.Text+ "', '" + 
    txtBankName.Text + "', '" + txtAccountNumber.Text + "', " + " '" + 
    txtIFSCCode.Text + "', " + " '" + txtBN1.Text + "', " + " '" + 
    txtAC1.Text + "', " + " '" + txtIFSC1.Text + "', " + " '" + 
    txtBN2.Text + "', " + " '" + txtAC2.Text + "', " + " '" + 
    txtIFSC2.Text + "', " + " '" + DateTime.Now + "')"; 

值插入MySQL数据库我想在一个特定的列进行自动increament说“ID”,但我想在餐桌上设置做到这一点在MySQL的向导,但而不是代码。可能吗? 我已经打勾在mysql表向导中标记了自动增加选项,但没有用。没有完成...

+1

您必须为您的INSERT语句中的ID列提供'NULL',或者提供一列列以填充并将ID列留在列表之外。 – Barmar

回答

0

如果您使用INT作为您的ID的数据类型,它应该工作正常。检查您用于ID列的数据类型。

+0

是的,我只使用INT数据类型..... @Amith Raj Shetty – user3531533

+0

粘贴您的表的创建语句在这里。我想我可以帮你解决这个问题。 –

0

这可以通过使用AUTO_INCREMENT做,试试这个

CREATE TABLE Fn_Registration (
    ID MEDIUMINT NOT NULL AUTO_INCREMENT, 
    ---Other columns--- 
    PRIMARY KEY (ID) 
) 
+0

但我已经创建了使用mysql wizqrd ....的表,但不是用querry ......... – user3531533

+0

您可以通过SHOW CREATE TABLE'Fn_Registration'提取查询;通过这个你可以得到表的创建查询,然后根据需要进行修改。 –

0

您不必插入您的ID列东西。

例如:

您的DB以下栏目:IDcol1col2col3其中ID标记自动incrase。

您的查询应该是这样的:

INSERT INTO tableName(col1, col2, col3) 
VALUES(val1, val2, val3); 

正如你可以看到不包括在查询中ID列,因为它已经被市场自动incrase本身。