from窗体用C#对SQL server数据库对dategrid view的删除添加的显示结果出不来
public void but添加_Click(object sender, EventArgs e)
{
int 学生学号 = Int32.Parse(textid1.Text);
string 学生姓名 = textname.Text;
string 院系 = textclass2.Text;
string 班级 = textclass3.Text;
int 班级人数 = Int32.Parse(textclassnum1.Text);
if (textid1.Text=="" || string.IsNullOrEmpty(学生姓名)|| string.IsNullOrEmpty(院系 ) || string.IsNullOrEmpty(班级) ||textclassnum1.Text=="")
{
MessageBox.Show("用户名或密码不能为空!");
return;
}
SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
scsb.DataSource = "LAPTOP-7DRB565C";
scsb.IntegratedSecurity = true;
scsb.InitialCatalog = "教材管理系统后台";
SqlConnection conn = new SqlConnection(scsb.ToString());
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
string strSQL = @"insert into studentinfo (学生学号,学生姓名,院系,班级,班级人数) values ('"
+ textid1.Text + "','" + textname.Text + "','" + textclass2.Text + "','" + textclass3.Text + "','" + textclassnum1.Text + "')";
SqlCommand comm = new SqlCommand(strSQL, conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
int n = da.Fill(ds, "studentinfoinfo");
if (n != 0)
{
textid1.Text = "";
textname.Text = "";
textclass2.Text = "";
textclass3.Text = "";
textclassnum1.Text = "";
}
else if (textname.TextLength > 16)
{
MessageBox.Show("学生姓名太长,我怕你记不住,请换个短的吧!", "提示");
}
else if (textid1.TextLength > 16)
{
MessageBox.Show("学号太长,请换个短的吧!", "提示");
}
else if (conn.State == System.Data.ConnectionState.Open)
{
MessageBox.Show("注册成功!");
conn.Close();
SqlConnection conn1 = new SqlConnection(scsb.ToString());
conn1.Open();
string strsql = @"SELECT 学生学号,学生姓名,班级,班级人数 FROM [dbo].[studentinfo]";
SqlCommand comm1 = new SqlCommand(strsql, conn1);
SqlDataAdapter sda = new SqlDataAdapter(comm1);
DataSet de = new DataSet();
dataGridView1.DataSource = sda.Fill(de, "studentinfo");
}
没有显示结果