110,566
社区成员
发帖
与我相关
我的任务
分享
private void 查询_Click(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection("server=WIN7U-20151010U;uid=sa;pwd=gsa4tb;database=xsxxdb");
SqlDataAdapter sda = new SqlDataAdapter();
try
{
if (ds.HasChanges())
{
sqlcon.Open();
//用SqlCommandBuilder自动为SqlDataAdapter生成Insert、Update、Delete命令
SqlCommandBuilder cb = new SqlCommandBuilder(sda);
sda.Update(ds);
dataGridView1.Update();
MessageBox.Show("保存成功!");
sqlcon.Close();
}
}
catch
{
MessageBox.Show("数据错误");
}
}
SqlConnection conn = new SqlConnection("server=WIN7U-20151010U;uid=sa;pwd=gsa4tb;database=xsxxdb");
// sda = new SqlDataAdapter("SELECT * FROM CJ where 科室='"+comboBox1.Text.ToString()+"' ", conn);
SqlCommand cmd = new SqlCommand("dy ", conn);
cmd.CommandType = CommandType.StoredProcedure;//
cmd.Parameters.Add("@mm", SqlDbType.VarChar, 100).Value = comboBox1.Text;
cmd.Parameters.Add("@nn", SqlDbType.VarChar, 100).Value = dateTimePicker1.Value.ToShortDateString();
cmd.Parameters.Add("@aa", SqlDbType.VarChar, 100).Value = dateTimePicker2.Value.ToShortDateString();
sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ds.Clear();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Show();
// dataGridView1.Columns[0].Visible = false;
dataGridView1.Rows[0].Selected = false;
SQLCOMMANDBULIDER(数据更新按钮):
SqlConnection sqlcon = new SqlConnection("server=WIN7U-20151010U;uid=sa;pwd=gsa4tb;database=xsxxdb");
try
{
if (ds.HasChanges())
{
sqlcon.Open();
//用SqlCommandBuilder自动为SqlDataAdapter生成Insert、Update、Delete命令
SqlCommandBuilder cb = new SqlCommandBuilder(sda);
sda.Update(ds);
dataGridView1.Update();
MessageBox.Show("保存成功!");
sqlcon.Close();
}
}
catch
{
MessageBox.Show("数据错误");
}
问题其实找到了,在数据库中的表是这个样子的:
显示出来就是1楼的样子。