Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / January 2006

Tip: Looking for answers? Try searching our database.

Problem reading data into Dataset

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Camper Joe - 31 Jan 2006 10:57 GMT
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?
serge calderara - 31 Jan 2006 11:16 GMT
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

> Here's my code:
>
[quoted text clipped - 41 lines]
>
> Any Ideas? Any Questions?
Camper Joe - 31 Jan 2006 11:47 GMT
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

> Hi,
>
[quoted text clipped - 52 lines]
> >
> > Any Ideas? Any Questions?
kashifahmed.bse.mg@gmail.com - 31 Jan 2006 12:14 GMT
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
Camper Joe - 31 Jan 2006 13:23 GMT
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.

> hi,
>
[quoted text clipped - 13 lines]
>
> kashif ahmed
serge calderara - 31 Jan 2006 12:21 GMT
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

> Hi.
>
[quoted text clipped - 62 lines]
> > >
> > > Any Ideas? Any Questions?
Camper Joe - 31 Jan 2006 13:27 GMT
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.

> if mySqlAdapter.Fill(ds1) generate the error then try to verify your SQl
> query within SQL querry to check if it works.
[quoted text clipped - 73 lines]
> > > >
> > > > Any Ideas? Any Questions?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.