Hi, Am new in VB.Net.I want to know how to call for data from SQL server usin code. Thanks

You can try this www.dreamincode.net/forums/topic/300487-creating-sql-server-stored-procedures-and-using-them-in-vbnet/

Thanks Jim. But can u help me. I get this message when i try running my project:
(Unable to cast object of type 'ADODB.InternalField' to type 'System.String'.)
Can u help me out. Thanks

If you post the code we can have a look. Please identify which line is throwing the error.

Dim con As New ADODB.Connection
Dim rec As New ADODB.Recordset

con.Open("DSN=BRM", "SA", "SA'")

rec.Open("select * from singin where id='" & Me.TextBox1.Text & "'", con)
If rec.EOF Then
    MsgBox("User ID does not exists", vbCritical)
    Me.TextBox1.Focus()
    Exit Sub
ElseIf Not rec.EOF Then
    Me.Label3.Text = rec.ToString("name")
    Exit Sub
End If

Actually, i use this code in vb 6.0 but it luks like i cant use the traditional ADO instead of ADO.Net

Your problem is likely in your connection string. Sample ADO code for SQL Server is

ListView1.Items.Clear()

Dim con As New ADODB.Connection
Dim rec As New ADODB.Recordset

con.Open("Driver={SQL Server};Server=.\SQLEXPRESS;Database=PUBS;Trusted_Connection=yes;")
rec.Open("SELECT au_lname,au_fname,zip FROM authors WHERE au_lname like 'S%'", con, CursorTypeEnum.adOpenStatic)

Do Until rec.EOF
    ListView1.Items.Add(New ListViewItem({rec("au_lname").Value, rec("au_fname").Value, rec("zip").Value}))
    rec.MoveNext()
Loop

rec.Close()
con.Close()

Thanks Jim. But if u refer to my code, this is where i have a problem;

Me.Label3.Text = rec.fields("name")

Am trying to display the name column of the record that i queried. Can you help me out with it?
Thanks

Try

rec("name").Value

Thank u very much Jim. Your code wroked perfectly. Thank once again. U genius.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.