【发布时间】:2013-06-23 00:20:26
【问题描述】:
我正在尝试将文本框值插入数据库。但是我被提示“关键字'table'附近的语法不正确”的错误 “cmd.ExecuteNonQuery();”有错误我的代码有什么问题?
下面是我的代码:
string query;
string str = "Data Source=blank blank blank;Initial Catalog=test;User ID=hello;Password=password";
SqlConnection con = new SqlConnection(str);
con.Open();
query = "INSERT INTO table dbo.url_map Values ('" + tbLongURL.Text + "')";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
您应该使用参数将值传递给您的 SqlCommand csharp-station.com/Tutorial/AdoDotNet/Lesson06