Private Sub showcombox()
sb.Remove(0, sb.Length)
sb.Append("select counter_name from counter")
Dim slecounter As String = sb.ToString()
com = New SqlCommand
With com
.CommandType = CommandType.Text
.CommandText = slecounter
.Connection = con
dr = .ExecuteReader()
While dr.Read
ComboBox1.Items.Add(dr("counter_name"))
End While
dr.Close()
End With
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text <> "" Then
Dim Da As New SqlDataAdapter
Dim Ds As New DataSet
Try
Da = New SqlDataAdapter("select counter_code from counter where counter_name='" + ComboBox1.SelectedItem.ToString() + "'", con)
Da.Fill(Ds, "counter")
dt = Ds.Tables("counter")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
txt_counter.Text = CStr(dt.Rows.Item(0).Item(0))
End If
End Sub
Tag : .NET, Ms SQL Server 2008, Win (Windows App), VS 2010 (.NET 4.x), Windows