110,534
社区成员
发帖
与我相关
我的任务
分享
if(dr.Read())
{
...............
}
判断,你应该自己理解程序逻辑,并且写出你的逻辑。
SqlConnection conn = Link.Getconn();
string sqlSNO = "select Dno from INInfo2 where Sno='" + textBox1.Text.Trim() + "'";
SqlCommand cmdSNO = new SqlCommand(sqlSNO, conn);
//SqlDataAdapter da1 = new SqlDataAdapter(cmdSNO);
object noObj = cmdSNO.ExecuteScalar();
if (noObj != null && !(noObj is DBNull))
{
string Dno = noObj.ToString();
string sqld = "select Now from DInfo where Dno='" + textBox1.Text.Trim() + "'";
SqlCommand cmdd = new SqlCommand(sqld, conn);
object nowObj = cmdd.ExecuteScalar();
if (nowObj != null && !(nowObj is DBNull))
{
int now = Convert.ToInt32(nowObj);
string udINInfo = "updata INInfo2 set Sname='" + textBox2.Text + "',Grade='" + textBox3.Text + "',College='" + textBox4.Text + "',Major='" + textBox5.Text + "',Dno='" + textBox6.Text + "',INtime='" + textBox7.Text + "' where Sno='" + textBox1.Text + "'";
SqlCommand cmdud = new SqlCommand(udINInfo, conn);
cmdud.ExecuteNonQuery();
string insert = "insert into CHANGEInfo Sname='" + textBox2.Text + "',Grade='" + textBox3.Text + "',College='" + textBox4.Text + "',Major='" + textBox5.Text + "',Dno='" + textBox6.Text + "',INtime='" + textBox7.Text + "' where Sno='" + textBox1.Text + "'";
SqlCommand cmdin = new SqlCommand(insert, conn);
cmdin.ExecuteNonQuery();
int newNow1 = now - 1;
int newNow2 = now + 1;
string DInfo1 = "updata DInfo set Max='6',Now='" + newNow1 + "' where Dno='" + Dno + "'";
string DInfo2 = "updata DInfo set Max='6',Now='" + newNow2 + "' where Dno='" + textBox6.Text + "'";
SqlCommand cmdd1 = new SqlCommand(DInfo1, conn);
SqlCommand cmdd2 = new SqlCommand(DInfo2, conn);
cmdd1.ExecuteNonQuery();
cmdd2.ExecuteNonQuery();
MessageBox.Show("换宿成功!", "提示");
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!", "提示");
}
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!", "提示");
}
if(dr.Read())
{
string Dno = (string)dr["Dno"];
string sqld = "select Now from DInfo where Dno='" + textBox1.Text.Trim() + "'";
SqlCommand cmdd = new SqlCommand(sqld, conn);
SqlDataReader myreader = cmdd.ExecuteReader(CommandBehavior.CloseConnection);
if(myreader.Read())
{
int now = (int)myreader["Now"];
if (dr.Read())
{
string udINInfo = "updata INInfo2 set Sname='" + textBox2.Text + "',Grade='" + textBox3.Text + "',College='" + textBox4.Text + "',Major='" + textBox5.Text + "',Dno='" + textBox6.Text + "',INtime='" + textBox7.Text + "' where Sno='" + textBox1.Text + "'";
SqlCommand cmdud = new SqlCommand(udINInfo,conn);
cmdud.ExecuteNonQuery();
string insert = "insert into CHANGEInfo Sname='" + textBox2.Text + "',Grade='" + textBox3.Text + "',College='" + textBox4.Text + "',Major='" + textBox5.Text + "',Dno='" + textBox6.Text + "',INtime='" + textBox7.Text + "' where Sno='" + textBox1.Text + "'";
SqlCommand cmdin = new SqlCommand(insert, conn);
cmdin.ExecuteNonQuery();
int newNow1 = now - 1;
int newNow2 = now + 1;
string DInfo1 = "updata DInfo set Max='6',Now='"+newNow1+"' where Dno='"+Dno+"'";
string DInfo2 = "updata DInfo set Max='6',Now='" + newNow2 + "' where Dno='" + textBox6.Text + "'";
SqlCommand cmdd1 = new SqlCommand(DInfo1,conn);
SqlCommand cmdd2 = new SqlCommand(DInfo2,conn);
cmdd1.ExecuteNonQuery();
cmdd2.ExecuteNonQuery();
MessageBox.Show("换宿成功!","提示");
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!","提示");
}
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!","提示");
}
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!","提示");
}
if(dr.Read())
{
string Dno = (string)dr["Dno"];
string sqld = "select Now from DInfo where Dno='" + textBox1.Text.Trim() + "'";
SqlCommand cmdd = new SqlCommand(sqld, conn);
SqlDataReader myreader = cmdd.ExecuteReader(CommandBehavior.CloseConnection);
int now = (int)myreader["Now"];
if (dr.Read())
{
string udINInfo = "updata INInfo2 set Sname='" + textBox2.Text + "',Grade='" + textBox3.Text + "',College='" + textBox4.Text + "',Major='" + textBox5.Text + "',Dno='" + textBox6.Text + "',INtime='" + textBox7.Text + "' where Sno='" + textBox1.Text + "'";
SqlCommand cmdud = new SqlCommand(udINInfo,conn);
cmdud.ExecuteNonQuery();
string insert = "insert into CHANGEInfo Sname='" + textBox2.Text + "',Grade='" + textBox3.Text + "',College='" + textBox4.Text + "',Major='" + textBox5.Text + "',Dno='" + textBox6.Text + "',INtime='" + textBox7.Text + "' where Sno='" + textBox1.Text + "'";
SqlCommand cmdin = new SqlCommand(insert, conn);
cmdin.ExecuteNonQuery();
int newNow1 = now - 1;
int newNow2 = now + 1;
string DInfo1 = "updata DInfo set Max='6',Now='"+newNow1+"' where Dno='"+Dno+"'";
string DInfo2 = "updata DInfo set Max='6',Now='" + newNow2 + "' where Dno='" + textBox6.Text + "'";
SqlCommand cmdd1 = new SqlCommand(DInfo1,conn);
SqlCommand cmdd2 = new SqlCommand(DInfo2,conn);
cmdd1.ExecuteNonQuery();
cmdd2.ExecuteNonQuery();
MessageBox.Show("换宿成功!","提示");
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!","提示");
}
}
else
{
MessageBox.Show("对不起,您输入的学生信息未录入系统!请确认学生信息!","提示");
}