删除datagridview中突出显示的fullrows的语句 [英] Delete statement for highlighted fullrows in datagridview

查看:78
本文介绍了删除datagridview中突出显示的fullrows的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我正在使用



* Visual Studio 2012

* MS Access 2013

* ADO.Net



我将DataGridView属性设置为正确的行为,以便用户获胜不小心弄乱了DataGridView显示器



ReadOnly = True

AllowUserToAddRows = False

AllowUsertoDeleteRows = True

AllowUserToOrderColumn = False

AllowUserToResizeColumns = False

AllowUserToResizeRows = False

RowHeadersWidthSizeMoe = DisableResizing

SelectionMode = FullRowSelect



这些是我声明的SQL语句



用于查看按钮

Hi guys.

I'm using

*Visual Studio 2012
*MS Access 2013
*ADO.Net

I set my DataGridView properties in their proper behavior so that the User won't accidentally mess the DataGridView Display

ReadOnly = True
AllowUserToAddRows = False
AllowUsertoDeleteRows = True
AllowUserToOrderColumn = False
AllowUserToResizeColumns = False
AllowUserToResizeRows = False
RowHeadersWidthSizeMoe = DisableResizing
SelectionMode = FullRowSelect

These are my declared SQL Statements

For View Button

Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
      ConnectDB()

      Dim Command As New OleDbCommand("SELECT * FROM Reservations ORDER BY ID", conn)
      Dim adapter As New OleDbDataAdapter
      Dim dt As New DataTable
      adapter.SelectCommand = Command
      adapter.Fill(dt)
      dgvDisplay.DataSource = dt
      dgvSizes()
      adapter.Dispose()
      Command.Dispose()
      conn.Close()
  End Sub





对于保存按钮:





For Save Button:

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

     If cboPlace.SelectedItem = "" Then
         MessageBox.Show("Please Pick Place")
         Exit Sub
     ElseIf cboFacility.SelectedItem = "" Then
         MessageBox.Show("Please choose Facility")
         Exit Sub
     ElseIf txtRequestor.Text = "" Then
         MessageBox.Show("Please enter the Requestor's Name")
         Exit Sub
     End If

     ConnectDB()

     Dim Command As New OleDbCommand("INSERT INTO Reservations ([Place],[Facility],[Date Reserved],[Time Start],[Time End],[Requestor],[Price],[Note])" & _
                                     "VALUES (@place, @facility, @datereserved, @timestart, @timeend, @requestor, @price, @note)", conn)

     Command.Parameters.AddWithValue("@place", cboPlace.SelectedItem)
     Command.Parameters.AddWithValue("@facility", cboFacility.SelectedItem)
     Command.Parameters.AddWithValue("@datereserved", datPick.Value.Date)
     Command.Parameters.AddWithValue("@timestart", timeStart.Value.ToString("hh:mm tt"))
     Command.Parameters.AddWithValue("@timeend", timeEnd.Value.ToString("hh:mm tt"))
     Command.Parameters.AddWithValue("@requestor", txtRequestor.Text)
     Command.Parameters.AddWithValue("@price", x.ToString("c"))
     Command.Parameters.AddWithValue("@note", txtNote.Text)

     Command.Connection = conn
     Command.ExecuteNonQuery()
     MsgBox("User Successfully Save!")
     Command.Dispose()
     conn.Close()
     Clear()
     btnView.PerformClick()





结束子



我想通过单击ID列删除特定突出显示的行一行,每行都有值。



这是我的代码,我希望你们添加一些特定的代码将它链接到ID值:





End Sub

I want to delete the specific highlighted rows by clicking the ID column, just one full row that has values on every row.

This is my code, i want you guys to add some specific code to link it to the ID value:

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

        ConnectDB()
        Command = New OleDbCommand("DELETE FROM Reservations where ID=", conn)
        Command.ExecuteNonQuery()
        MsgBox("User Successfully delete!")
        Command.Dispose()
        conn.Close()
        btnView.PerformClick()
    End Sub





我尝试过:



我确实将ID = Autonumber值链接到其标签ID文本并使用UPDATE语句,但它只删除了顶部的值而不是所需的突出显示的行。



例如



点击删除按钮



< execute code =>



会发生什么?

ID = 1被删除而不是所选ID = 5,突出显示的行。



请帮助我,因为我正在寻找解决方案。



我需要吗?在我的保存按钮中使用INSERT或UPDATE语句?



请尽快回答,很多人会回答我的问题。提前谢谢:)



What I have tried:

I did link the ID = Autonumber value to its Label ID text and use UPDATE Statement but its only deleting the values from the top and not the desired highlighted rows.

For e.g.

Click Delete button

<execute code="">

What happens is ?
ID = 1 was deleted not the chosen ID = 5, the Highlighted row.

Please help me cause I'm looking for a solution.

Do I need to use INSERT , or UPDATE Statements in my Save button?

Please answer ASAP, Many kudos those who would answer my problem . Advance Thank you :)

推荐答案

试试这个,



如果找不到标签,先找到它。



Private Sub btnDelete_Click(发送者为对象,e为EventArgs)处理btnDelete.Click



ConnectDB ()

int id = lblid.text;

Command = New OleDbCommand(DELETE FROM Reservations where ID = id,conn)

Command.ExecuteNonQuery()

MsgBox(用户成功删除!)

Command.Dispose()

conn.Close()

btnView.PerformClick()



End Sub
try this,

if lable is not find,first find it.

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

ConnectDB()
int id=lblid.text;
Command = New OleDbCommand("DELETE FROM Reservations where ID=id", conn)
Command.ExecuteNonQuery()
MsgBox("User Successfully delete!")
Command.Dispose()
conn.Close()
btnView.PerformClick()

End Sub


好的但是我想删除单击ID列的特定突出显示的行,只有一行在每一行都有值。
Ok tried but I want to delete the specific highlighted rows by clicking the ID column, just one full row that has values on every row.


这篇关于删除datagridview中突出显示的fullrows的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆