G
gordon
Hi,
I am using vb.net and loading up some SAS data into some text boxes based on
an id selected in a combo box. I have a button that I wish to use to clear
all the text box values and to set the combo box to a non-value "Select
one...". I cannot get the boxes to clear. Several attemps have allowed me
to clear the last box but not the others.
Any help appreciated
my code is :
Public cnsas As New OleDb.OleDbConnection
Public ds As DataSet = New DataSet
Private Sub GetData()
Dim SASLibrary As String = "C:\"
Try
cnsas.ConnectionString = _
"Provider=sas.LocalProvider.9.1;Data Source=" & SASLibrary
cnsas.Open()
Dim cmd As OleDb.OleDbCommand = cnsas.CreateCommand
cmd.CommandType = CommandType.TableDirect
cmd.CommandText = "Products"
Dim oleDA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(cmd)
oleDA.Fill(ds, "Products")
ComboBox1.DataSource = ds.Tables("Products")
ComboBox1.DisplayMember = _
ds.Tables("Products").Columns("ProductID").ToString()
PopulateTextboxes(0)
Catch ex As Exception
MessageBox.Show( _
"Type : " & ex.GetType.ToString() & vbCr & _
"Message = " & ex.Message)
End Try
End Sub
Sub PopulateTextboxes(ByVal RowID As Integer)
Dim drow1 As DataRow = ds.Tables("Products").Rows(RowID)
TextBox1.Text = drow1("ProductName")
textbox2.Text = drow1("UnitPrice")
TextBox3.Text = drow1("QuantityperUnit")
TextBox4.Text = drow1("UnitsInStock").ToString()
End Sub
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetData()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox1.Text = "Choose one..."
PopulateTextboxes(ComboBox1.SelectedIndex)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
End
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ComboBox1.Text = "Choose one..."
TextBox4.Text = (" ").ToString()
TextBox4.Text = (" ").ToString()
TextBox4.Text = (" ").ToString()
TextBox4.Text = (" ").ToString()
End Sub
End Class
I am using vb.net and loading up some SAS data into some text boxes based on
an id selected in a combo box. I have a button that I wish to use to clear
all the text box values and to set the combo box to a non-value "Select
one...". I cannot get the boxes to clear. Several attemps have allowed me
to clear the last box but not the others.
Any help appreciated
my code is :
Public cnsas As New OleDb.OleDbConnection
Public ds As DataSet = New DataSet
Private Sub GetData()
Dim SASLibrary As String = "C:\"
Try
cnsas.ConnectionString = _
"Provider=sas.LocalProvider.9.1;Data Source=" & SASLibrary
cnsas.Open()
Dim cmd As OleDb.OleDbCommand = cnsas.CreateCommand
cmd.CommandType = CommandType.TableDirect
cmd.CommandText = "Products"
Dim oleDA As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(cmd)
oleDA.Fill(ds, "Products")
ComboBox1.DataSource = ds.Tables("Products")
ComboBox1.DisplayMember = _
ds.Tables("Products").Columns("ProductID").ToString()
PopulateTextboxes(0)
Catch ex As Exception
MessageBox.Show( _
"Type : " & ex.GetType.ToString() & vbCr & _
"Message = " & ex.Message)
End Try
End Sub
Sub PopulateTextboxes(ByVal RowID As Integer)
Dim drow1 As DataRow = ds.Tables("Products").Rows(RowID)
TextBox1.Text = drow1("ProductName")
textbox2.Text = drow1("UnitPrice")
TextBox3.Text = drow1("QuantityperUnit")
TextBox4.Text = drow1("UnitsInStock").ToString()
End Sub
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetData()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox1.Text = "Choose one..."
PopulateTextboxes(ComboBox1.SelectedIndex)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
End
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ComboBox1.Text = "Choose one..."
TextBox4.Text = (" ").ToString()
TextBox4.Text = (" ").ToString()
TextBox4.Text = (" ").ToString()
TextBox4.Text = (" ").ToString()
End Sub
End Class