求解,SQL插入语句是否有问题,我运行是提示 ‘(’附近有语法错误

[复制链接]
查看11 | 回复4 | 2011-6-23 01:22:24 | 显示全部楼层 |阅读模式
string cons = @"Data Source=GKJIANG-PC\SQLEXPRESS;Initial Catalog=学生管理;Integrated Security=True";

string sm = string.Format(comboBox1.SelectedItem.ToString() + "_学生信息");

//string sql = string.Format ( @"INSERT INTO {0}VALUES ( {1}, '{2}','{3}',{4},'{5}','{6}' )", sm, Convert.ToInt32(textBox3.Text), textBox4.Text, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text, textBox8.Text);

string sql = " INSERT INTO" + sm + " VALUES (123132 ,'nani','n',23,'1989.12.1','ds')";


SqlConnection con = new SqlConnection(cons);

//SqlDataAdapter da = new SqlDataAdapter(sql, con);


SqlCommand com = new SqlCommand();




com.Connection = con;

com.CommandType = CommandType.Text;

com.CommandText = sql;

MessageBox.Show("4");

try

{

con.Open();

int s=com.ExecuteNonQuery();


MessageBox.Show("数据添加成功");

}

catch (System.Exception ex)

{

MessageBox.Show(ex.Message);

}

回复

使用道具 举报

千问 | 2011-6-23 01:22:24 | 显示全部楼层
string sql = " INSERT INTO" + sm + " VALUES (123132 ,'nani','n',23,'1989.12.1','ds')"; ( {1}, '{2}','{3}',{4},'{5}','{6}' )这里用的小括号的输入法错误,是()
不是()...
回复

使用道具 举报

千问 | 2011-6-23 01:22:24 | 显示全部楼层
程序中的多个 ( 看上去不一样,是不是输入法不对,导致SQL无法识别。...
回复

使用道具 举报

千问 | 2011-6-23 01:22:24 | 显示全部楼层
你用的括号是全角的(),改为半角括号就行 ()....
回复

使用道具 举报

千问 | 2011-6-23 01:22:24 | 显示全部楼层
Values 前面应该有一个空格吧!...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行