110,535
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SQL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int current = 0;
DataSet dsStu = new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "学生信息管理";
this.txtStuID.ReadOnly = true;
}
private void BtnRead_Click(object sender, EventArgs e)
{
string conStr = "Server=(local);Database=test;integrated security=true";
//SqlConnection cn = new SqlConnection(conStr);
SqlDataAdapter sda = new SqlDataAdapter("select * from StuInfo", conStr);
SqlDataAdapter sda1 = new SqlDataAdapter("select * from StuCourse", conStr);
sda.Fill(dsStu,"StuInfo");
sda1.Fill(dsStu,"StuCourse");
ShowInfo();
}
private void ShowInfo()
{
this.txtStuID.Text = dsStu.Tables[0].Rows[current][0].ToString().Trim();
this.txtStuName.Text = dsStu.Tables["StuInfo"].Rows[current][1].ToString().Trim();
if (Convert.ToInt16(dsStu.Tables["StuInfo"].Rows[current][2]) == 1)
{
this.chkStuSexM.Checked = true;
this.chkStuSexF.Checked = false;
}
else
{
this.chkStuSexM.Checked = false;
this.chkStuSexF.Checked = true;
}
this.dtpStuBirth.Value = (DateTime)dsStu.Tables["StuInfo"].Rows[current][3];
this.txtStuAdd.Text = dsStu.Tables["StuInfo"].Rows[current][4].ToString().Trim();
this.txtStuTel.Text = dsStu.Tables["StuInfo"].Rows[current][5].ToString().Trim();
this.dtpStuAD.Value = (DateTime)dsStu.Tables["StuCourse"].Rows[current][1];
this.txtStuMajor.Text = dsStu.Tables["StuCourse"].Rows[current][2].ToString().Trim();
}
}
}
namespace SQL
{
public partial class Form1 : Form
{
private int current = 0;
DataTable dtStuInfo = new DataTable();
DataTable dtStuCourse = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "学生信息管理";
this.txtStuID.ReadOnly = true;
}
private void BtnRead_Click(object sender, EventArgs e)
{
string conStr = "Server=(local);Database=test;integrated security=true";
//SqlConnection cn = new SqlConnection(conStr);
SqlDataAdapter sda = new SqlDataAdapter("select * from StuInfo", conStr);
SqlDataAdapter sda1 = new SqlDataAdapter("select * from StuCourse", conStr);
sda.Fill(dtStuInfo);
sda1.Fill(dtStuCourse);
ShowInfo();
}
private void ShowInfo()
{
DataRow currentStuInfoRow = dtStuInfo.Rows[current];
DataRow currentStuCourseRow = dtStuCourse.Rows[current];
this.txtStuID.Text = currentStuInfoRow["StuID"].ToString().Trim();
this.txtStuName.Text = currentStuInfoRow[1].ToString().Trim();
if (Convert.ToInt16(currentStuInfoRow[2]) == 1)
{
this.chkStuSexM.Checked = true;
this.chkStuSexF.Checked = false;
}
else
{
this.chkStuSexM.Checked = false;
this.chkStuSexF.Checked = true;
}
this.dtpStuBirth.Value = (DateTime)currentStuInfoRow[3];
this.txtStuAdd.Text = currentStuInfoRow[4].ToString().Trim();
this.txtStuTel.Text = currentStuInfoRow[5].ToString().Trim();
this.dtpStuAD.Value = (DateTime)currentStuCourseRow[1];
this.txtStuMajor.Text = currentStuCourseRow[2].ToString().Trim();
}
}
}