ASP.NET向动态数据表中插入数据

#region开始组卷protectedvoidButton1_Click(objectsender,EventArgse){stringsjName=txtSJName... #region 开始组卷
protected void Button1_Click(object sender, EventArgs e)
{
string sjName = txtSJName.Text;//试卷名称
SqlConnection sqlconstr = new SqlConnection();
sqlconstr.ConnectionString = "Server=03BC87212BC243A;Database=ShiJuan;User id=sa;PWD='123456'";
sqlconstr.Open();

#region 创建试卷列表
string sjname = "USE ShiJuan CREATE TABLE " + sjName.ToString() + "(que_type char(10) NULL,que_subject varchar(50) NULL,optionA varchar(50) NULL,optionB varchar(50) NULL,optionC varchar(50) NULL,optionD varchar(50) NULL,que_answer varchar(50) NULL)";
if (txtSJName.Text != "")
{
SqlCommand cmd = new SqlCommand(sjname, sqlconstr);
SqlDataReader myReader = cmd.ExecuteReader();
myReader.Close();
}
else
{
Response.Write("<script>alert('请输入试卷名称!')</script>");

}

#endregion

//抽取单选题
for (int i = 0; i < gvSchoose.Rows.Count; i++)
{
if (((CheckBox)gvSchoose.Rows[i].FindControl("cbPitch")).Checked)
{

string writeSQL = " INSERT INTO"+sjName.ToString ()+"(que_type, que_subject,optionA,optionB,optionC,optionD,que_answer)values('单选题','" + gvSchoose.Rows[i].Cells[2].Text + "','" + gvSchoose.Rows[i].Cells[3].Text + "','" + gvSchoose.Rows[i].Cells[4].Text + "','" + gvSchoose.Rows[i].Cells[5].Text + "','" + gvSchoose.Rows[i].Cells[6].Text + "','" + gvSchoose.Rows[i].Cells[7].Text + "')";
SqlCommand cmd1 = new SqlCommand(writeSQL, sqlconstr);
cmd1.ExecuteReader();

}
}
每次运行时在此处有错误,错误提示为:对象名 'INTOwangziqi' 无效。
"wangziqi"是输入的表明,即sjName变量的值。
string writeSQL = " INSERT INTO"+sjName.ToString ()+"(que_type, que_subject,optionA,optionB,optionC,optionD,que_answer)values('单选题','" + gvSchoose.Rows[i].Cells[2].Text + "','" + gvSchoose.Rows[i].Cells[3].Text + "','" + gvSchoose.Rows[i].Cells[4].Text + "','" + gvSchoose.Rows[i].Cells[5].Text + "','" + gvSchoose.Rows[i].Cells[6].Text + "','" + gvSchoose.Rows[i].Cells[7].Text + "')";

请高手指点,谢谢!
展开
 我来答
leon382
2010-08-05 · TA获得超过1064个赞
知道小有建树答主
回答量:1744
采纳率:0%
帮助的人:983万
展开全部
你在 INSERT INTO 处留一个空格出来 如下
string writeSQL = " INSERT INTO "+sjName.ToString ()+" (que_type, que_subject,optionA,optionB,optionC,optionD,que_answer)values('单选题','" + gvSchoose.Rows[i].Cells[2].Text + "','" + gvSchoose.Rows[i].Cells[3].Text + "','" + gvSchoose.Rows[i].Cells[4].Text + "','" + gvSchoose.Rows[i].Cells[5].Text + "','" + gvSchoose.Rows[i].Cells[6].Text + "','" + gvSchoose.Rows[i].Cells[7].Text + "')";
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式