另,程序运行中没有报出任何错误!在线等,立即给分!多谢!
private void btnAdd_Click(object sender, System.EventArgs e)
{
string ids = this.txtNames.Text.Trim();
int count = this.StudentIDs(ids).Length;
string month = this.SelectMonthForAdd.SelectedValue;
float points = Convert.ToSingle ( this.txtPoint.Text.Trim() );
string type = this.SelectType.SelectedItem.Text;
string description = this.txtDescription.Text.Trim();
string listID = this.txtListID.Text.Trim();
string [] id = this.StudentIDs(ids);
string names = "";
for ( int i = 0 ; i < count ; i ++)
{
DataRow dr = this.ds.OperationList.NewRow();
string studentName = this.GetName( id[i]);
if ( studentName == null )
{
Response.Write ("你输入的学号"+id[i]+"错误,请检查后重新输入!");
return;
}
else
{
dr["StudentName"] = studentName;
Response.Write( studentName);
names += studentName + ",";
}
dr["ListID"] = listID;
dr["StudentID"] = id[i];
dr["Points"] = points;
dr["OperatingType"] = type;
dr["Description"] = description;
dr["CurrentDate"] = System.DateTime.Now;
ds.OperationList.Rows.Add ( dr );
Response.Write ( id[i].ToString() );
}
this.daOperationList.Update ( ds,"OperationList");
this.ds.OperationList.AcceptChanges();
this.Label5.Visible = true;
this.Label5.Text = "成功对" + count.ToString() +"个人进行了分值操作!他们是:" + names;
}
8 个解决方案
#1
DataRow dr = this.ds.OperationList.NewRow();
if (dr.read())
{
string studentName = this.GetName( id[i]);
if ( studentName == null )
{
Response.Write ("你输入的学号"+id[i]+"错误,请检查后重新输入!");
return;
}
else
{
dr["StudentName"] = studentName;
Response.Write( studentName);
names += studentName + ",";
}
dr["ListID"] = listID;
dr["StudentID"] = id[i];
dr["Points"] = points;
dr["OperatingType"] = type;
dr["Description"] = description;
dr["CurrentDate"] = System.DateTime.Now;
ds.OperationList.Rows.Add ( dr );
Response.Write ( id[i].ToString() );
}
this.daOperationList.Update ( ds,"OperationList");
this.ds.OperationList.AcceptChanges();
this.Label5.Visible = true;
this.Label5.Text = "成功对" + count.ToString() +"个人进行了分值操作!他们是:" + names;
}
}
if (dr.read())
{
string studentName = this.GetName( id[i]);
if ( studentName == null )
{
Response.Write ("你输入的学号"+id[i]+"错误,请检查后重新输入!");
return;
}
else
{
dr["StudentName"] = studentName;
Response.Write( studentName);
names += studentName + ",";
}
dr["ListID"] = listID;
dr["StudentID"] = id[i];
dr["Points"] = points;
dr["OperatingType"] = type;
dr["Description"] = description;
dr["CurrentDate"] = System.DateTime.Now;
ds.OperationList.Rows.Add ( dr );
Response.Write ( id[i].ToString() );
}
this.daOperationList.Update ( ds,"OperationList");
this.ds.OperationList.AcceptChanges();
this.Label5.Visible = true;
this.Label5.Text = "成功对" + count.ToString() +"个人进行了分值操作!他们是:" + names;
}
}
#2
要先判断dr有没有值!!
if (dr.read())
然后才可以使用!!
if (dr.read())
然后才可以使用!!
#3
先谢谢楼上的!不过小弟不懂了,既然是NewRow当然没有值了,我要赋值给它丫!再说,这个read()方法,是什么意思?
#4
this.daOperationList.Update ( ds,"OperationList");
看看daOperationList的insertCommand的CommandText是什么??
看看daOperationList的insertCommand的CommandText是什么??
#5
//
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO OperationList(CurrentDate, Description, ListID, OperatingType, Points" +
", StudentID) VALUES (?, ?, ?, ?, ?, ?)";
this.oleDbInsertCommand2.Connection = this.conn;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("CurrentDate", System.Data.OleDb.OleDbType.DBDate, 0, "CurrentDate"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 50, "Description"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("ListID", System.Data.OleDb.OleDbType.VarWChar, 50, "ListID"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("OperatingType", System.Data.OleDb.OleDbType.VarWChar, 50, "OperatingType"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Points", System.Data.OleDb.OleDbType.Single, 0, "Points"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("StudentID", System.Data.OleDb.OleDbType.VarWChar, 250, "StudentID"));
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO OperationList(CurrentDate, Description, ListID, OperatingType, Points" +
", StudentID) VALUES (?, ?, ?, ?, ?, ?)";
this.oleDbInsertCommand2.Connection = this.conn;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("CurrentDate", System.Data.OleDb.OleDbType.DBDate, 0, "CurrentDate"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 50, "Description"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("ListID", System.Data.OleDb.OleDbType.VarWChar, 50, "ListID"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("OperatingType", System.Data.OleDb.OleDbType.VarWChar, 50, "OperatingType"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Points", System.Data.OleDb.OleDbType.Single, 0, "Points"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("StudentID", System.Data.OleDb.OleDbType.VarWChar, 250, "StudentID"));
#6
不好意思!!看错了!!我以为你写的dr是DataReader!!看错了!!
不好意思!!!
你看一下这个代码!!
DataSet data=new DataSet();
StreamReader sr=new StreamReader(Server.MapPath("xml2.xml"));
StreamWriter sw;
DataTable dt=new DataTable();
string str;
DataRow dr;
str=sr.ReadLine();
data.ReadXml(sr);
sr.Close();
dt=data.Tables["Report"];
dr=dt.NewRow();
dr["ID"]=DS.Tables["List"].Rows[a][0];
dr["Title"]=DS.Tables["List"].Rows[a][1];
dr["Words"]=DS.Tables["List"].Rows[a][2];
dr["UpDater"]=DS.Tables["List"].Rows[a][3];
dt.Rows.Add(dr);
sw=new StreamWriter(Server.MapPath("xml2.xml"),false);
sw.WriteLine(str);
sw.Close();
sw=new StreamWriter(Server.MapPath("xml2.xml"),true);
data.WriteXml(sw);
sw.Close();
不好意思!!!
你看一下这个代码!!
DataSet data=new DataSet();
StreamReader sr=new StreamReader(Server.MapPath("xml2.xml"));
StreamWriter sw;
DataTable dt=new DataTable();
string str;
DataRow dr;
str=sr.ReadLine();
data.ReadXml(sr);
sr.Close();
dt=data.Tables["Report"];
dr=dt.NewRow();
dr["ID"]=DS.Tables["List"].Rows[a][0];
dr["Title"]=DS.Tables["List"].Rows[a][1];
dr["Words"]=DS.Tables["List"].Rows[a][2];
dr["UpDater"]=DS.Tables["List"].Rows[a][3];
dt.Rows.Add(dr);
sw=new StreamWriter(Server.MapPath("xml2.xml"),false);
sw.WriteLine(str);
sw.Close();
sw=new StreamWriter(Server.MapPath("xml2.xml"),true);
data.WriteXml(sw);
sw.Close();
#7
我明白了,高人!!!
#8
无论如何,谢谢两位高手相助!给分了。
#1
DataRow dr = this.ds.OperationList.NewRow();
if (dr.read())
{
string studentName = this.GetName( id[i]);
if ( studentName == null )
{
Response.Write ("你输入的学号"+id[i]+"错误,请检查后重新输入!");
return;
}
else
{
dr["StudentName"] = studentName;
Response.Write( studentName);
names += studentName + ",";
}
dr["ListID"] = listID;
dr["StudentID"] = id[i];
dr["Points"] = points;
dr["OperatingType"] = type;
dr["Description"] = description;
dr["CurrentDate"] = System.DateTime.Now;
ds.OperationList.Rows.Add ( dr );
Response.Write ( id[i].ToString() );
}
this.daOperationList.Update ( ds,"OperationList");
this.ds.OperationList.AcceptChanges();
this.Label5.Visible = true;
this.Label5.Text = "成功对" + count.ToString() +"个人进行了分值操作!他们是:" + names;
}
}
if (dr.read())
{
string studentName = this.GetName( id[i]);
if ( studentName == null )
{
Response.Write ("你输入的学号"+id[i]+"错误,请检查后重新输入!");
return;
}
else
{
dr["StudentName"] = studentName;
Response.Write( studentName);
names += studentName + ",";
}
dr["ListID"] = listID;
dr["StudentID"] = id[i];
dr["Points"] = points;
dr["OperatingType"] = type;
dr["Description"] = description;
dr["CurrentDate"] = System.DateTime.Now;
ds.OperationList.Rows.Add ( dr );
Response.Write ( id[i].ToString() );
}
this.daOperationList.Update ( ds,"OperationList");
this.ds.OperationList.AcceptChanges();
this.Label5.Visible = true;
this.Label5.Text = "成功对" + count.ToString() +"个人进行了分值操作!他们是:" + names;
}
}
#2
要先判断dr有没有值!!
if (dr.read())
然后才可以使用!!
if (dr.read())
然后才可以使用!!
#3
先谢谢楼上的!不过小弟不懂了,既然是NewRow当然没有值了,我要赋值给它丫!再说,这个read()方法,是什么意思?
#4
this.daOperationList.Update ( ds,"OperationList");
看看daOperationList的insertCommand的CommandText是什么??
看看daOperationList的insertCommand的CommandText是什么??
#5
//
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO OperationList(CurrentDate, Description, ListID, OperatingType, Points" +
", StudentID) VALUES (?, ?, ?, ?, ?, ?)";
this.oleDbInsertCommand2.Connection = this.conn;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("CurrentDate", System.Data.OleDb.OleDbType.DBDate, 0, "CurrentDate"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 50, "Description"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("ListID", System.Data.OleDb.OleDbType.VarWChar, 50, "ListID"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("OperatingType", System.Data.OleDb.OleDbType.VarWChar, 50, "OperatingType"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Points", System.Data.OleDb.OleDbType.Single, 0, "Points"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("StudentID", System.Data.OleDb.OleDbType.VarWChar, 250, "StudentID"));
// oleDbInsertCommand2
//
this.oleDbInsertCommand2.CommandText = "INSERT INTO OperationList(CurrentDate, Description, ListID, OperatingType, Points" +
", StudentID) VALUES (?, ?, ?, ?, ?, ?)";
this.oleDbInsertCommand2.Connection = this.conn;
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("CurrentDate", System.Data.OleDb.OleDbType.DBDate, 0, "CurrentDate"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Description", System.Data.OleDb.OleDbType.VarWChar, 50, "Description"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("ListID", System.Data.OleDb.OleDbType.VarWChar, 50, "ListID"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("OperatingType", System.Data.OleDb.OleDbType.VarWChar, 50, "OperatingType"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("Points", System.Data.OleDb.OleDbType.Single, 0, "Points"));
this.oleDbInsertCommand2.Parameters.Add(new System.Data.OleDb.OleDbParameter("StudentID", System.Data.OleDb.OleDbType.VarWChar, 250, "StudentID"));
#6
不好意思!!看错了!!我以为你写的dr是DataReader!!看错了!!
不好意思!!!
你看一下这个代码!!
DataSet data=new DataSet();
StreamReader sr=new StreamReader(Server.MapPath("xml2.xml"));
StreamWriter sw;
DataTable dt=new DataTable();
string str;
DataRow dr;
str=sr.ReadLine();
data.ReadXml(sr);
sr.Close();
dt=data.Tables["Report"];
dr=dt.NewRow();
dr["ID"]=DS.Tables["List"].Rows[a][0];
dr["Title"]=DS.Tables["List"].Rows[a][1];
dr["Words"]=DS.Tables["List"].Rows[a][2];
dr["UpDater"]=DS.Tables["List"].Rows[a][3];
dt.Rows.Add(dr);
sw=new StreamWriter(Server.MapPath("xml2.xml"),false);
sw.WriteLine(str);
sw.Close();
sw=new StreamWriter(Server.MapPath("xml2.xml"),true);
data.WriteXml(sw);
sw.Close();
不好意思!!!
你看一下这个代码!!
DataSet data=new DataSet();
StreamReader sr=new StreamReader(Server.MapPath("xml2.xml"));
StreamWriter sw;
DataTable dt=new DataTable();
string str;
DataRow dr;
str=sr.ReadLine();
data.ReadXml(sr);
sr.Close();
dt=data.Tables["Report"];
dr=dt.NewRow();
dr["ID"]=DS.Tables["List"].Rows[a][0];
dr["Title"]=DS.Tables["List"].Rows[a][1];
dr["Words"]=DS.Tables["List"].Rows[a][2];
dr["UpDater"]=DS.Tables["List"].Rows[a][3];
dt.Rows.Add(dr);
sw=new StreamWriter(Server.MapPath("xml2.xml"),false);
sw.WriteLine(str);
sw.Close();
sw=new StreamWriter(Server.MapPath("xml2.xml"),true);
data.WriteXml(sw);
sw.Close();
#7
我明白了,高人!!!
#8
无论如何,谢谢两位高手相助!给分了。