数据库表插入时提示system.data.sqlclient.sqlexception'('附近有语法错误是怎么回事?代码如下:
objectbianhao=textBox2.Text;objectjiaoshibianhao=textBox3.Text;SqlCommandmycmd2;DataS...
object bianhao = textBox2.Text;
object jiaoshibianhao = textBox3.Text;
SqlCommand mycmd2;
DataSet findinfo;
SqlDataAdapter sd2;
string ss = "Data Source = WQI-PC\\SQLEXPRESS;database = 在线作业提交;Integrated Security = SSPI;";//注意转义字符
try
{
SqlConnection thisConnection = new SqlConnection(ss); //只能对sql的连接
thisConnection.Open();
MessageBox.Show("数据库正被连接");
mycmd2=new SqlCommand ("insert into 教师课程对应表(CourseNum,TeachNum)values('"+bianhao +"','"+jiaoshibianhao +"')",thisConnection );
findinfo = new DataSet();
sd2 = new SqlDataAdapter(mycmd2);
sd2.Fill(findinfo, "教师课程对应表");
MessageBox.Show("添加成功");
}
catch (Exception e1)
{
MessageBox.Show(e1.GetBaseException().ToString());
}
其中表的主键设为自增1的,我没处理,插不进去,怎么回事啊? 展开
object jiaoshibianhao = textBox3.Text;
SqlCommand mycmd2;
DataSet findinfo;
SqlDataAdapter sd2;
string ss = "Data Source = WQI-PC\\SQLEXPRESS;database = 在线作业提交;Integrated Security = SSPI;";//注意转义字符
try
{
SqlConnection thisConnection = new SqlConnection(ss); //只能对sql的连接
thisConnection.Open();
MessageBox.Show("数据库正被连接");
mycmd2=new SqlCommand ("insert into 教师课程对应表(CourseNum,TeachNum)values('"+bianhao +"','"+jiaoshibianhao +"')",thisConnection );
findinfo = new DataSet();
sd2 = new SqlDataAdapter(mycmd2);
sd2.Fill(findinfo, "教师课程对应表");
MessageBox.Show("添加成功");
}
catch (Exception e1)
{
MessageBox.Show(e1.GetBaseException().ToString());
}
其中表的主键设为自增1的,我没处理,插不进去,怎么回事啊? 展开
2个回答
2013-03-16
展开全部
你的表名是中文的?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询