Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button based on data 1

Status
Not open for further replies.

holidayIT

IS-IT--Management
Apr 2, 2004
138
US
I am very very new to vb.net (but olf to vb), and i am having all kinds of problems with .net

the one i am having now is with two radio buttons. i have a field in a sql server table that contains a 1 or 2, and two radio buttons for open and close. i want 1 as open and two as close, but everytime i try a new way to associaate them, it doesn't work. i have a sub that checks the value of a variable, and if the variable contains a 1 ro 2, then checked or not( pretty straight forward). but trying to get the variable to contain the data seems to not be working.

how can i get the variable to contain the data? and where should i call the sub to change on every row. if anyone knows of a better way, i'd really appreciate it.
 
Well calling the sub depends on your requirement. The code snippet below works on Form Load event.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Create SqlConnection Object.
Dim myConn As New SqlConnection("server=YourServer;database=YourDataBase;uid=YourUserID;pwd=YourPassword;")
'Initialize DataSet Object.
Dim myDS As New DataSet()
'Create SqlDataAdapter Object.
Dim myDA As SqlDataAdapter
'Variable to hold value from the database table.
Dim myValue As Integer

'Open Connection.
myConn.Open()

'Initialize SqlDataAdapter Object with SQL String and SqlConnection Obejct.
myDA = New SqlDataAdapter("SELECT YourField FROM YourTable", myConn)
'Fill the DataSet with data from the database table.
myDA.Fill(myDS, "YourTable")

'Close Connection.
myConn.Close()

'Save the value from database table in your variabke
myValue = myDS.Tables(0).Rows(0).Item(0)

'Check the RadioButton.
Select Case myValue
Case 1
optOpen.Checked = True
Case 2
optClose.Checked = True
End Select

End Sub

Email: pankajmsm@yahoo.com
 
thank you sooo much.
you are a god among men.
 
ok, maybe i shoulda checked first, but it tells me that SqlConnection is not defined (neither is SqlDataAdapter). I feel pretty stupid. please help
 
i added the SqlClient before SqlConnection, and it worked except that i do not supply a username and password, so it failed (said i didn't have a trusted connection). I do not want to put username and password in. any idea how to do this????? Shouldn't i be able to not type in anything for uid and pwd???? won't it default to ads login or somehting??? am i completely off base???
 
nevermind. i need to stop posting questions and then finding out the answers on my own. i needed the "interated security keyword after the database in my connection string. if anyone else has this problem, solve it like this:

("server=YourServer;database=YourDataBase;Integrated Security=SSPI")
 
Integrated Security or Trusted_Connection specifies whether the connection is to be a secure connection or not.

valid values are 'true', 'false', and 'sspi', which is equivalent to 'true'.




Email: pankajmsm@yahoo.com
 
thanks, i just had one quick question. when i use the table(0).row(0).item(0), it works for only that record (or row) is there a way to get the data dynamically??? i tried to leave out row, and of course it didn't work. i need the data to change with the focus. does that make sense? i am useing the binding.add("text", "table.field") for the other objects, is there a way to do that with variables so that i can type the table and field so i don't have to figure out the index of the item???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top