Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my table
id       name
1       abc
2       xyz

it i enter 1 then respective value "abc" display in different text box???
VB
Private Sub butsea_Click(sender As Object, e As EventArgs) Handles butsea.Click
 
        Dim dset As New DataSet
        Dim da As SqlDataAdapter
        Dim myCmd As New SqlCommand
 
        Try
       myConn.ConnectionString = "Data Source=THEONE\PARTH;Initial Catalog=testdatabase;Integrated Security=True;"
            myConn.Open()
 
            Dim avalue As String = (InputBox("Input Student Id", "Search Student")).ToString
            txt_id.Text = avalue
            da = New SqlDataAdapter("SELECT * FROM studentdetails where student_id= '" & txt_id.Text & "", myConn)
            If dset.Tables(0).Rows.Count > 0 Then
               'what should i write here
            Else
                MsgBox("No Record Found")
            End If
           
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            myConn.Close()
        End Try
 
    End Sub
Posted

If dset.Tables(0).Rows.Count > 0 Then
              txt_name.Text = dset.Tables(0).Rows(0)("name").ToString()
            Else
                MsgBox("No Record Found")
            End If
 
Share this answer
 
v2
0) Don't put data access code in your UI code; write a Data Access Layer and a business logic layer
1) Use parameterized queries, not concatenation
2) Don't use * if you only want one value (or a few)
3) Don't use a DataSet to get one value
4) Don't use a DataAdapter to get one value

5) I recommend using ExecuteScalar
 
Share this answer
 
Comments
Parth Akbari 24-Aug-13 15:10pm    
how to use ExecuteScalar ?? it i want u access more then one value then i can use ExecuteScalar???
PIEBALDconsult 24-Aug-13 15:57pm    
ExecuteScalar returns one value; which is what you specified in the title.

http://msdn.microsoft.com/en-us/library/system.data.idbcommand.executescalar.aspx
Parth Akbari 24-Aug-13 16:21pm    
thx ,this is gud information about ExecutScalar
but there is one move column and i want to access that value( a ) then i can use ExecuteScalar???
my table
id name class
1 abc a
2 xyz b
PIEBALDconsult 24-Aug-13 16:29pm    
So you want two values, not just one. You could use ExecuteScalar if you don't mind making two calls, but if you want both values at once, then you want something else.
But I still say that DataAdapter and DataSet are too heavy for what you want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900