473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
6 1392
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
1
by: Angel \Java\ Lopez | last post by:
Hi people! I'm running a Visual Studio 2005, Professional, on Windows XP Professional. I've found a little big problem, reading a DataSet. If I try: ds.ReadXml("c:\data.xml") it raises...
4
by: shibeta | last post by:
Hello, I have problem with DataGridView and BindingSource. I have created DataSet and added TableData to it with manualy created columns (without DataAdapter - I'm not using MSSQL). On the Form I...
4
by: David | last post by:
Hi, (Sorry for duplicate post, finger trouble before I finished...) using C# 1.1 I am writing a winform app that collects a dataset from a webservice. At the same time I collect the data,...
2
by: Martin Madreza | last post by:
Hi, I have a problem with reading an XmlSchema with Frameowk 2.0 and an own DataType. I found no example (searching two days). What I do is: DataSet dataSet = new DataSet();...
6
by: Bill Nguyen | last post by:
I'm reading a CSV file with the date colum formatted as "YYMMDD" -"070310" when viewed in notepad or similar trext editor. However, in my app, using ODBCReader, the column value becomes "70310"...
7
by: David | last post by:
Hi, using C# asp.net 1.1 I am having a problem. If I use the code below, but have null passed as the PostingGuid, then by the time I get to fill the dataset, I have "an object is not set to...
13
by: slinky | last post by:
I'm working on a problem with a form with 6 textboxes and a submit button for adding data to an Access database.I changed a few things and got it down to 1 error!. I have a Sub Page_Load and a Sub...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.