说明:下面的所有字段都被成功写入,但只有StudentName字段为空。而且我用Response.Write()方法已经确认GetName()方法已成功获得姓名值,可是dr["StudentName]= studentName语句似乎没有生效????为何????另,程序运行中没有报出任何错误!在线等,立即给分!多谢!
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;
}
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;
}
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())
然后才可以使用!!
看看daOperationList的insertCommand的CommandText是什么??
// 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"));
不好意思!!!
你看一下这个代码!!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();