rinu.urs@gmail.com
New member
- Joined
- Sep 16, 2009
- Messages
- 2
- Programming Experience
- Beginner
hi all
I am new to vb.net. I am trying to connect to the database
but its throwing an exception on dataAdapter1.Fill(ds)
can any one please see this and advice me about it
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As New SqlConnection
Dim myCommand As SqlCommand
myConnection.ConnectionString = "Data Source=localhost\SQLEXPRESS;Initial Catalog=hr;User ID=sa;Password=deedee"
Try
myConnection.Open()
myCommand = New SqlCommand("Select * from dbo.user", myConnection)
Dim dataAdapter1 As New SqlDataAdapter(myCommand)
Dim ds As New DataSet()
dataAdapter1.Fill(ds)
MsgBox(ds.Tables(0).Rows(0).Item(1))
myConnection.Close()
Catch ex As Exception
MsgBox("connection error")
End Try
End Sub
End Class
The problem is here dataAdapter1.Fill(ds) as soon as it reaches here it throws the exception
kindly advice
I am new to vb.net. I am trying to connect to the database
but its throwing an exception on dataAdapter1.Fill(ds)
can any one please see this and advice me about it
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As New SqlConnection
Dim myCommand As SqlCommand
myConnection.ConnectionString = "Data Source=localhost\SQLEXPRESS;Initial Catalog=hr;User ID=sa;Password=deedee"
Try
myConnection.Open()
myCommand = New SqlCommand("Select * from dbo.user", myConnection)
Dim dataAdapter1 As New SqlDataAdapter(myCommand)
Dim ds As New DataSet()
dataAdapter1.Fill(ds)
MsgBox(ds.Tables(0).Rows(0).Item(1))
myConnection.Close()
Catch ex As Exception
MsgBox("connection error")
End Try
End Sub
End Class
The problem is here dataAdapter1.Fill(ds) as soon as it reaches here it throws the exception
kindly advice