Problem reading data into Dataset

G

Guest

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").Caption
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?
 
G

Guest

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
 
G

Guest

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
 
K

kashifahmed.bse.mg

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
 
G

Guest

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
 
G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top