using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using OnLineExam.BusinessLogicLayer;
using OnLineExam.DataAccessLayer;public partial class Teacher_WorkExam : System.Web.UI.Page
{
string ExamID = "";//试卷编号
string ExamName = "";//试卷名
string schoose;//选择题数
string application;//操作题数
string CourseID = "";
string connection = "Server=.;database=InNetEaxm;Integrated Security=true";
SqlConnection sc = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
BaseDBControl dbContol = new BaseDBControl();
sc.ConnectionString = connection;
ExamID = Request.QueryString["ExamID"];
// int ExamID = Convert.ToInt32(Session["ExamID"]);
SqlCommand cmd = new SqlCommand("select * from ExamInfo where ExamID='" + ExamID + "' and ExamName='"+ExamName+"'", sc);
sc.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
schoose = sdr["SChooseNum"].ToString();
application = sdr["ApplicationNum"].ToString();
CourseID = sdr["CourseID"].ToString();
}
sc.Close();
if (!IsPostBack)
{
lblSchoose.Text = "共有" + schoose + "道题";
lblApplication.Text = "共有" + application + "道题";
} } protected void cbPitch_CheckedChanged(object sender, EventArgs e)
{
int i = 0;
for (int j = 0; j < gvSchoose.Rows.Count; j++)
if (((CheckBox)gvSchoose.Rows[j].FindControl("cbPitch")).Checked)
i++;
lblSchoose1.Text = i.ToString() + "题";
}
protected void btnOK_Click(object sender, EventArgs e)
{
BaseDBControl dbContol = new BaseDBControl();
for (int i = 0; i < gvSchoose.Rows.Count; i++)
{
if (((CheckBox)gvSchoose.Rows[i].FindControl("cbPitch")).Checked)
{
int aa = Int32.Parse((gvSchoose.DataKeys[i].Value).ToString().Trim());
sc.Open();
SqlCommand cmd = new SqlCommand("select ID from SingleProblem where ID="+aa, sc);
string str = cmd.ExecuteScalar().ToString().Trim();
string sqlstr="insert into [WorkExam](ExamID,ScID,Type,CourseID)values('" + ExamID.Trim() + "',
'" + str.Trim() + "','选择','" + CourseID.Trim() + "')";
SqlCommand cmd1 = new SqlCommand(sqlstr, sc);
int count= cmd1.ExecuteNonQuery();
sc.Close();
}
}
}提示str.Trim() 未将对象引用设置到实例,应该怎样将str中的数据引用
补充:如何将另一个页面数据保存到当前运行页
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using OnLineExam.BusinessLogicLayer;
using OnLineExam.DataAccessLayer;public partial class Teacher_WorkExam : System.Web.UI.Page
{
string ExamID = "";//试卷编号
string ExamName = "";//试卷名
string schoose;//选择题数
string application;//操作题数
string CourseID = "";
string connection = "Server=.;database=InNetEaxm;Integrated Security=true";
SqlConnection sc = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
BaseDBControl dbContol = new BaseDBControl();
sc.ConnectionString = connection;
ExamID = Request.QueryString["ExamID"];
// int ExamID = Convert.ToInt32(Session["ExamID"]);
SqlCommand cmd = new SqlCommand("select * from ExamInfo where ExamID='" + ExamID + "' and ExamName='"+ExamName+"'", sc);
sc.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
schoose = sdr["SChooseNum"].ToString();
application = sdr["ApplicationNum"].ToString();
CourseID = sdr["CourseID"].ToString();
}
sc.Close();
if (!IsPostBack)
{
lblSchoose.Text = "共有" + schoose + "道题";
lblApplication.Text = "共有" + application + "道题";
} } protected void cbPitch_CheckedChanged(object sender, EventArgs e)
{
int i = 0;
for (int j = 0; j < gvSchoose.Rows.Count; j++)
if (((CheckBox)gvSchoose.Rows[j].FindControl("cbPitch")).Checked)
i++;
lblSchoose1.Text = i.ToString() + "题";
}
protected void btnOK_Click(object sender, EventArgs e)
{
BaseDBControl dbContol = new BaseDBControl();
for (int i = 0; i < gvSchoose.Rows.Count; i++)
{
if (((CheckBox)gvSchoose.Rows[i].FindControl("cbPitch")).Checked)
{
int aa = Int32.Parse((gvSchoose.DataKeys[i].Value).ToString().Trim());
sc.Open();
SqlCommand cmd = new SqlCommand("select ID from SingleProblem where ID="+aa, sc);
string str = cmd.ExecuteScalar().ToString().Trim();
string sqlstr="insert into [WorkExam](ExamID,ScID,Type,CourseID)values('" + ExamID.Trim() + "',
'" + str.Trim() + "','选择','" + CourseID.Trim() + "')";
SqlCommand cmd1 = new SqlCommand(sqlstr, sc);
int count= cmd1.ExecuteNonQuery();
sc.Close();
}
}
}提示str.Trim() 未将对象引用设置到实例,应该怎样将str中的数据引用
补充:如何将另一个页面数据保存到当前运行页
解决方案 »
- VS2005未能映射路径,在线急等!!
- DataTalbe中的问题
- 关于DATALIST使用
- 请教各位大锅,关于 ITypeProvider 的实现问题【C#、RuleSetDialog、ITypeProvider 】
- 如何C#的16进位转10进位
- 大家好,C#连接SQL2000问题
- 在C#中,RichTextBox的行高怎么设置?
- 线程同步的问题, 创建一个类的2个对象实例,对这个类里的method是否要采用lock的方法,想知道对象创建后是否是共用同一份method code?
- async await的问题
- 为什么输出的结果是乱码的?C#(IT菜鸟的提问)
- winform 按扭问题!
- 用C#怎样连续发送一些数据,而且是异步的
的结果是什么
如:int aa = Int32.Parse((gvSchoose.DataKeys[i].Value).ToString().Trim());
sc.Open();
SqlCommand cmd = new SqlCommand("select ID from SingleProblem where ID="+aa, sc);
string str = cmd.ExecuteScalar().ToString().Trim();
然后插入到另一张表中