irvank
New member
- Joined
- Nov 18, 2015
- Messages
- 3
- Programming Experience
- 1-3
i have a problem that i cant solve, so i need to ask
problem :
i have a data grid view, and i have make custom column for it
i have to input some IDB to datagridview manually and its automatically get data from mysql database, how to do that ?
i have tried this
it can automatically input first data,but it say some error
line 69 : mysqlConnection.ConnectionString = ServerString
it doesnt error when i didnt use MetroGrid1.Rows(dgrow).Cells("Name").Value = bc.Item(3) , but without this i cant input automatically using only IDB
please help me solving this problem, Thanks in advance
problem :
i have a data grid view, and i have make custom column for it
VB.NET:
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(4) {New DataColumn("IDB", GetType(String)), New DataColumn("Name", GetType(String)), New DataColumn("Price", GetType(Integer)), New DataColumn("Amount", GetType(Integer)), New DataColumn("Total", GetType(Integer))})
Me.MetroGrid1.DataSource = dt
i have to input some IDB to datagridview manually and its automatically get data from mysql database, how to do that ?
i have tried this
VB.NET:
Private Sub inputdata(sender As Object, e As DataGridViewCellEventArgs) Handles MetroGrid1.CellValueChanged
Dim dgrow As Integer = 0
Try
If MetroGrid1.Rows(baris).Cells("IDB").Value Then
mysqlConnection.ConnectionString = ServerString
mysqlConnection.Open()
Dim bc As MySqlDataReader
cmdmysql.CommandText = "SELECT * FROM product where IDB = '" + MetroGrid1.Rows(dgrow).Cells("IDB").Value + "'"
cmdmysql.Connection = mysqlConnection
bc = cmdmysql.ExecuteReader
If bc.HasRows Then
bc.Read()
MetroGrid1.Rows(dgrow).Cells("Name").Value = bc.Item(3)
MetroGrid1.Rows(dgrow).Cells("Price").Value = bc.Item(4)
Label3.Text = bc.Item(3)
Label4.Text = bc.Item(4)
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
it can automatically input first data,but it say some error
MySql.Data.MySqlClient.MySqlException (0x80004005): Not allowed to change the 'ConnectionString' property while the connection (state=Open). at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception)
at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex)
at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value)
at SCS_MetroDesign.Pembayaran.gantidata(Object sender, DataGridViewCellEventArgs e) in:line 69
line 69 : mysqlConnection.ConnectionString = ServerString
it doesnt error when i didnt use MetroGrid1.Rows(dgrow).Cells("Name").Value = bc.Item(3) , but without this i cant input automatically using only IDB
please help me solving this problem, Thanks in advance