Start New Discussion within our Software Development Community

I am trying to select data from a database in the based on a condition....Its just a simple select SQL query

SELECT playerid FROM player WHERE username = 'John'

Therefore, from this I would like to store John's playerid to a variable and then use this variable.

Below is my attempt but not getting anywhere:

Dim da As OleDb.OleDbDataAdapter
        Dim sql2 As String
        Dim test
        sql2 = "SELECT playerid FROM player WHERE username = 'John'"

        test= New OleDb.OleDbDataAdapter(sql2, myCon)

        test = da.GetFillParameters()

        'AddData("Player1ID, Player2ID", "'" & tbxPlayerID.Text & "', '" & test & '")

What would be the best way to achieve what I'm trying to do? maybe there is a much simple metho.

im an new to this so, any help would be much appreciated. i am using Microsoft Visual Basic 2008 Express Edition....


you can use this:

Dim mycon As New SqlClient.SqlConnection()
            Dim mycom As SqlClient.SqlDataAdapter

            mycon = New SqlClient.SqlConnection("Data Source=TOSHIBA-USER;Initial Catalog=test2;Persist Security Info=True;User ID=sa;Password=pass")
            mycom = New SqlClient.SqlDataAdapter("select playerid  from player where username  =" & TextBox1.Text & "", mycon)

            Dim ds As DataSet = New DataSet()
            Dim id_ As String = ds.Tables(0).Rows(0).Item(0).ToString

In the future in my way of think is better use a datasets for these cases

I hope this help u ....(sorry, my english is not good)

This article has been dead for over six months. Start a new discussion instead.