0

Hi Everyone,
I have a datagrid, columns name location code,account code,account name(read only),
if i give the account no to check the acc. no in database and also automatically give the
account name in another cell(i.e. account name cell)

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by saravanarajan
0

' while form load bind the data in datagird control
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As SqlConnection = New SqlConnection("server=shailu;uid=sa;pwd=;database=pubs")
Dim sadapt As SqlDataAdapter = New SqlDataAdapter("select * from account", con)
Dim ds As DataSet = New DataSet
sadapt.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
End Sub

'Bind the data in datagrid control by accountcode from the user through textbox

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As SqlConnection = New SqlConnection("server=shailu;uid=sa;pwd=;database=pubs")
Dim sadapt As SqlDataAdapter = New SqlDataAdapter("select * from account where accountcode='" & TextBox1.Text & "'", con)
Dim ds As DataSet = New DataSet
sadapt.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
End Sub

'While change values in a cell(account code) required data will bind
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Dim con As SqlConnection = New SqlConnection("server=shailu;uid=sa;pwd=;database=pubs")
Dim sadapt As SqlDataAdapter = New SqlDataAdapter("select * from account where accountcode like '%" & DataGrid1.Item(DataGrid1.CurrentRowIndex, 0) & "%'", con)
Dim ds As DataSet = New DataSet
sadapt.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
End Sub

Best Regards,
shailu:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.