簡體   English   中英

SQL Server插入錯誤:列名或提供的值數與表定義C#不匹配

[英]SQL Server Insert Error: Column name or number of supplied values does not match table definition c#

我想使用Visual Studio 2015將數據添加到表中,但出現此錯誤:

An exception of type "System.Data.SqlClient.SqlException" occurred in System.Data.dll but was not processed in user code
Column name or number of supplied values does not match table definition.

這是我的代碼:

    protected void btSignup_Click(object sender, EventArgs e)
{
    String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
    using (SqlConnection con = new SqlConnection(CS))
    {
        SqlCommand cmd = new SqlCommand("insert into Users values('" + tbUname.Text + "','" + tbPass.Text + "','" + tbEmail.Text + "','" + tbName.Text + "')",con);
        con.Open();
        cmd.ExecuteNonQuery();
    }
}

這是我的桌子

這是信息

這是您的代碼:

insert into User
     values('" + tbUname.Text + "','" + tbPass.Text + "','" + tbEmail.Text + "','" + tbName.Text + "')"

使用insert ,應始終包括列名。 並且,將值放入查詢字符串時,應使用參數。

修復代碼后,您的問題將消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM