c# winfrom中,怎样通过datagrideview实现删除,添加,修改数据库?

c# winfrom中,怎样通过datagrideview实现删除,添加,修改数据库?,第1张

private void button1_Click(object sender, EventArgs e)

{

string zhiri = maskedTextBox1.Text

if (radioButton1.Checked == true)

{

sql = "select * from ******* where ******* like '%" + zhiri + "%'"

cmd = new SqlCommand(sql, Class1.me_conn)

sdr = cmd.ExecuteReader()

if (!sdr.Read())

{

MessageBox.Show("********")

maskedTextBox1.Clear()

maskedTextBox1.Focus()

}

//sdr.Close()

else

{

sdr.Close()

dataGridView1.Visible = true

SqlDataAdapter sda = new SqlDataAdapter(sql, Class1.me_conn)

ds = new DataSet()

sda.Fill(ds)

dataGridView1.DataSource = ds.Tables[0]

}

sdr.Close()

}

if (radioButton2.Checked == true)

{

sql = "select * from **** where **** like '%" + zhiri + "%'"

cmd = new SqlCommand(sql, Class1.me_conn)

sdr = cmd.ExecuteReader()

if (!sdr.Read())

{

MessageBox.Show("**********")

maskedTextBox1.Clear()

maskedTextBox1.Focus()

}

//sdr.Close()

else

{

sdr.Close()

dataGridView1.Visible = true

SqlDataAdapter sda = new SqlDataAdapter(sql, Class1.me_conn)

ds = new DataSet()

sda.Fill(ds)

dataGridView1.DataSource = ds.Tables[0]

}

sdr.Close()

}

if (radioButton3.Checked == true)

{

sql = "select * from ******* where ******* like '%" + zhiri + "%'"

cmd = new SqlCommand(sql,Class1.me_conn)

sdr = cmd.ExecuteReader()

if (!sdr.Read())

{

MessageBox.Show("*********")

maskedTextBox1.Clear()

maskedTextBox1.Focus()

}

//sdr.Close()

else

{

sdr.Close()

dataGridView1.Visible = true

SqlDataAdapter sda = new SqlDataAdapter(sql, Class1.me_conn)

ds = new DataSet()

sda.Fill(ds)

dataGridView1.DataSource = ds.Tables[0]

}

sdr.Close()

}

//sdr.Close()

else

{

sdr.Close()

dataGridView1.Visible = true

SqlDataAdapter sda = new SqlDataAdapter(sql, Class1.me_conn)

ds = new DataSet()

sda.Fill(ds)

dataGridView1.DataSource = ds.Tables[0]

}

sdr.Close()

}

这是一个单击事件下的带吗!还有其中****的地方为项目相应的词语

添加;On Error Resume Next

cmdDel.Enabled = Not cmdDel.Enabled

cmdUpDate.Enabled = Not cmdUpDate.Enabled

cmdEsc.Enabled = Not cmdEsc.Enabled

cmdFind.Enabled = Not cmdFind.Enabled

If cmdAdd.Caption = "添加" Then

cmdAdd.Caption = "确定"

Data1.Recordset.AddNew

Data1.Recordset.Update

Text1.SetFocus

Else

cmdAdd.Caption = "添加"

Adodc1.Recordset.MoveLast

End If

删除 On Error Resume Next

Data1.Recordset.Delete

Data1.Recordset.MoveNext

If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9540234.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存