Home > Net > The use of vb.net in the datagridview
The use of vb.net in the datagridview
Time:10-07
How to query button can find I need conditions, such as start date and end date, according to the data in the datagridview between how the information recorded at the same time, changes to the database, the code, I am novice, thank you! All this points to the
CodePudding user response:
According to the start date and end date first query to the DataTable, then your datagridview1. The DataSource=dt, can display, the following code, using SQl Server database, You modified use Updata update
Dim mySQL As String
MySQL="SELECT SN AS model, StartTime AS the start time, EndTime AS end time, IsOK AS state" & amp; _ "FROM tb_Data_ChaXiaoU" & amp; _ "WHERE StartTime>='" & amp; Format (DateTimePicker1. Value, "yyyy - MM - dd) & amp; "00:00:00. 000 'AND EndTime & lt;='" & amp; Format (DateTimePicker2. Value, "yyyy - MM - dd) & amp; "23:59:59. 000 '" 'dataadapters executing SQL statements Dim adapter As New SqlClient. SqlDataAdapter (mySQL, myCon) Dim dt As New DataTable (" myQuery ")
Adapter. The Fill (dt) Dgv_DataQuery. The DataSource=dt
Modify the
'to write data in the database Dim mySQLstr As String MySQLstr="UPDATE tb_Data_ChaXiaoU_Model SET SAP=@ _SAP, UCount=@ _UCount WHERE Model=@ _Model" Dim cmd1 As New SqlClient. SqlCommand (mySQLstr myCon) Cmd1. The Parameters. The Add (New SqlClient. SqlParameter (" @ _Model, "txt_Model. Text)) Cmd1. The Parameters. The Add (New SqlClient. SqlParameter (" @ _SAP, "txt_SAP. Text)) Cmd1. The Parameters. The Add (New SqlClient. SqlParameter (" @ _UCount ", Val (txt_UCount. Text))) Try MyCon. The Open () Cmd1. ExecuteNonQuery () MyCon. Close () Catch the ex As Exception MyCon. Close () End the Try
CodePudding user response:
It seems hard, I suggest you VB.NET SQL operation under the baidu