467,911 Members | 1,370 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,911 developers. It's quick & easy.

Problem reading data into Dataset

Here's my code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim db As New SqlConnection
Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &
txtUsername.Text & "'"
Dim ds1 As DataSet = New DataSet()

db.ConnectionString = "Data Source=.\SQLExpress;Integrated
Security=True;User
Instance=True;database=permit50;AttachDBFilename=| DataDirectory|aspnetdb.mdf;"
db.Open()

Dim mySqlAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, db)
mySqlAdapter.Fill(ds1, "users")

If ds1.Tables("strUsername").Rows.Count = 0 Then
lblError.Text = "Invalid Username"
Else
If ds1.Tables("USers").Columns("strPassword").Caption <> Not
txtPassword.Text Then
lblError.Text = "Invalid Password"
Else
Session("tblUsersID") =
ds1.Tables("Users").Columns("tblUsersID").Caption
Session("strFirstname") =
ds1.Tables("Users").Columns("strFirstname").Captio n
Session("strUsername") =
ds1.Tables("Users").Columns("strUsername").Caption
Response.Redirect("welcome.aspx")
End If
End If
End Sub

My Error is on the part that goes: mySqlAdapter.Fill(ds1, "users")

My error message is:System.data.SqlClientException: Invalid pbject name
'users'.

Users does exist in my database. I am using SQL Server 2005 Express.

Any Ideas? Any Questions?
Jan 31 '06 #1
  • viewed: 1204
Share:
6 Replies
Hi,

Check if your Adapter object is really valid and then verify also your ds1
object
Try to remove second parameter of the Fill method to verify if it able to
fill data in default dataset table name
When you create a dataset obect it has a default table named Table1
When you use the fill method as you do, the second string could be anything
and will be used as the dataset table name object

"Camper Joe" wrote:
Here's my code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim db As New SqlConnection
Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &
txtUsername.Text & "'"
Dim ds1 As DataSet = New DataSet()

db.ConnectionString = "Data Source=.\SQLExpress;Integrated
Security=True;User
Instance=True;database=permit50;AttachDBFilename=| DataDirectory|aspnetdb.mdf;"
db.Open()

Dim mySqlAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, db)
mySqlAdapter.Fill(ds1, "users")

If ds1.Tables("strUsername").Rows.Count = 0 Then
lblError.Text = "Invalid Username"
Else
If ds1.Tables("USers").Columns("strPassword").Caption <> Not
txtPassword.Text Then
lblError.Text = "Invalid Password"
Else
Session("tblUsersID") =
ds1.Tables("Users").Columns("tblUsersID").Caption
Session("strFirstname") =
ds1.Tables("Users").Columns("strFirstname").Captio n
Session("strUsername") =
ds1.Tables("Users").Columns("strUsername").Caption
Response.Redirect("welcome.aspx")
End If
End If
End Sub

My Error is on the part that goes: mySqlAdapter.Fill(ds1, "users")

My error message is:System.data.SqlClientException: Invalid pbject name
'users'.

Users does exist in my database. I am using SQL Server 2005 Express.

Any Ideas? Any Questions?

Jan 31 '06 #2
Hi.

Thanks for the advice.
I've tried it. Whether I leave the second part of the .fill blank, or put in
"table1", it still
gives me the error System.Data.SqlClient.SqlException: Invalid object name
'users'.
CJ

"serge calderara" wrote:
Hi,

Check if your Adapter object is really valid and then verify also your ds1
object
Try to remove second parameter of the Fill method to verify if it able to
fill data in default dataset table name
When you create a dataset obect it has a default table named Table1
When you use the fill method as you do, the second string could be anything
and will be used as the dataset table name object

"Camper Joe" wrote:
Here's my code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim db As New SqlConnection
Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &
txtUsername.Text & "'"
Dim ds1 As DataSet = New DataSet()

db.ConnectionString = "Data Source=.\SQLExpress;Integrated
Security=True;User
Instance=True;database=permit50;AttachDBFilename=| DataDirectory|aspnetdb.mdf;"
db.Open()

Dim mySqlAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, db)
mySqlAdapter.Fill(ds1, "users")

If ds1.Tables("strUsername").Rows.Count = 0 Then
lblError.Text = "Invalid Username"
Else
If ds1.Tables("USers").Columns("strPassword").Caption <> Not
txtPassword.Text Then
lblError.Text = "Invalid Password"
Else
Session("tblUsersID") =
ds1.Tables("Users").Columns("tblUsersID").Caption
Session("strFirstname") =
ds1.Tables("Users").Columns("strFirstname").Captio n
Session("strUsername") =
ds1.Tables("Users").Columns("strUsername").Caption
Response.Redirect("welcome.aspx")
End If
End If
End Sub

My Error is on the part that goes: mySqlAdapter.Fill(ds1, "users")

My error message is:System.data.SqlClientException: Invalid pbject name
'users'.

Users does exist in my database. I am using SQL Server 2005 Express.

Any Ideas? Any Questions?

Jan 31 '06 #3

hi,

u may assign a name to dataset at creating time..

dim ds as dataset=new dataset("user1")

and please use try catch exception with finally....

u may better just declare variable first, then use try catch exception
and open connection

allocate memory for adapter then dataset and do further ur business
programming...

this all may help u to solve prob....

kashif ahmed

Jan 31 '06 #4

if mySqlAdapter.Fill(ds1) generate the error then try to verify your SQl
query within SQL querry to check if it works.

If it is, the from your code juste for test run the query "SELECT * FROM
user" just to check

If it works, verify your SQL string when it is build

regards
serge
"Camper Joe" wrote:
Hi.

Thanks for the advice.
I've tried it. Whether I leave the second part of the .fill blank, or put in
"table1", it still
gives me the error System.Data.SqlClient.SqlException: Invalid object name
'users'.
CJ

"serge calderara" wrote:
Hi,

Check if your Adapter object is really valid and then verify also your ds1
object
Try to remove second parameter of the Fill method to verify if it able to
fill data in default dataset table name
When you create a dataset obect it has a default table named Table1
When you use the fill method as you do, the second string could be anything
and will be used as the dataset table name object

"Camper Joe" wrote:
Here's my code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim db As New SqlConnection
Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &
txtUsername.Text & "'"
Dim ds1 As DataSet = New DataSet()

db.ConnectionString = "Data Source=.\SQLExpress;Integrated
Security=True;User
Instance=True;database=permit50;AttachDBFilename=| DataDirectory|aspnetdb.mdf;"
db.Open()

Dim mySqlAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, db)
mySqlAdapter.Fill(ds1, "users")

If ds1.Tables("strUsername").Rows.Count = 0 Then
lblError.Text = "Invalid Username"
Else
If ds1.Tables("USers").Columns("strPassword").Caption <> Not
txtPassword.Text Then
lblError.Text = "Invalid Password"
Else
Session("tblUsersID") =
ds1.Tables("Users").Columns("tblUsersID").Caption
Session("strFirstname") =
ds1.Tables("Users").Columns("strFirstname").Captio n
Session("strUsername") =
ds1.Tables("Users").Columns("strUsername").Caption
Response.Redirect("welcome.aspx")
End If
End If
End Sub

My Error is on the part that goes: mySqlAdapter.Fill(ds1, "users")

My error message is:System.data.SqlClientException: Invalid pbject name
'users'.

Users does exist in my database. I am using SQL Server 2005 Express.

Any Ideas? Any Questions?

Jan 31 '06 #5
Thanks for the support.

After reading up on datasets, I saw that if your SELECT query doesn't return
any rows, the table object doesn't get created.

CJ.

"ka****************@gmail.com" wrote:

hi,

u may assign a name to dataset at creating time..

dim ds as dataset=new dataset("user1")

and please use try catch exception with finally....

u may better just declare variable first, then use try catch exception
and open connection

allocate memory for adapter then dataset and do further ur business
programming...

this all may help u to solve prob....

kashif ahmed

Jan 31 '06 #6
Thanks for the support.

After reading up on datasets, I saw that if your SELECT query doesn't return
any rows, the table object doesn't get created.

CJ.

"serge calderara" wrote:

if mySqlAdapter.Fill(ds1) generate the error then try to verify your SQl
query within SQL querry to check if it works.

If it is, the from your code juste for test run the query "SELECT * FROM
user" just to check

If it works, verify your SQL string when it is build

regards
serge
"Camper Joe" wrote:
Hi.

Thanks for the advice.
I've tried it. Whether I leave the second part of the .fill blank, or put in
"table1", it still
gives me the error System.Data.SqlClient.SqlException: Invalid object name
'users'.
CJ

"serge calderara" wrote:
Hi,

Check if your Adapter object is really valid and then verify also your ds1
object
Try to remove second parameter of the Fill method to verify if it able to
fill data in default dataset table name
When you create a dataset obect it has a default table named Table1
When you use the fill method as you do, the second string could be anything
and will be used as the dataset table name object

"Camper Joe" wrote:

> Here's my code:
>
> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Dim db As New SqlConnection
> Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &
> txtUsername.Text & "'"
> Dim ds1 As DataSet = New DataSet()
>
> db.ConnectionString = "Data Source=.\SQLExpress;Integrated
> Security=True;User
> Instance=True;database=permit50;AttachDBFilename=| DataDirectory|aspnetdb.mdf;"
> db.Open()
>
> Dim mySqlAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, db)
> mySqlAdapter.Fill(ds1, "users")
>
> If ds1.Tables("strUsername").Rows.Count = 0 Then
> lblError.Text = "Invalid Username"
> Else
> If ds1.Tables("USers").Columns("strPassword").Caption <> Not
> txtPassword.Text Then
> lblError.Text = "Invalid Password"
> Else
> Session("tblUsersID") =
> ds1.Tables("Users").Columns("tblUsersID").Caption
> Session("strFirstname") =
> ds1.Tables("Users").Columns("strFirstname").Captio n
> Session("strUsername") =
> ds1.Tables("Users").Columns("strUsername").Caption
> Response.Redirect("welcome.aspx")
> End If
> End If
>
>
> End Sub
>
>
>
> My Error is on the part that goes: mySqlAdapter.Fill(ds1, "users")
>
> My error message is:System.data.SqlClientException: Invalid pbject name
> 'users'.
>
> Users does exist in my database. I am using SQL Server 2005 Express.
>
> Any Ideas? Any Questions?
>
>

Jan 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Scott M. Lyon | last post: by
1 post views Thread by Angel \Java\ Lopez | last post: by
4 posts views Thread by David | last post: by
6 posts views Thread by Bill Nguyen | last post: by
7 posts views Thread by David | last post: by
13 posts views Thread by slinky | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.