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 + "')";
请高手指点,谢谢! 展开
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 + "')";
请高手指点,谢谢! 展开
1个回答
展开全部
你在 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 + "')";
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 + "')";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询