Question Dataset Exception

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
 
Instead of just displaying "connection error" when there's an error you should actually get some information about the error itself. Then you might be aboe to fix it for yourself. The best way to get maximum information is to get the result of ex.ToString, which includes the error message and the full stack trace.
 
hi

I have solved the problem. the key word name user is what i have used in the
select statement which is not allowed so i have used select * from [user] insted
its working fine
 
Back
Top