473,396 Members | 2,024 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,396 software developers and data experts.

DataReader Problem

44
Dear Friends

This is Sweatha. Right now I am working in the ASP.NET 2005 with VB coding & the back end is SQL SERVER 2000.

My dilemma is

I have to design a form with 2 DropDownListboxes. I have to load the ‘names of the theater’ on the 1st DropDownListbox & the names of the movie on the second DropDownListbox. That’s why I have created 2 tables named ‘theater’ and ‘movie’ on sql server 2000. The ‘theater’ table consists of 2 fields

Table Name: Theater
-------------------
tid tname
--------------------
t1 udhayam
t2 devi
t3 cinipriya
t4 dhanam
t5 pallavi
--------------------
The 'movie' table has 2 fields

Table Name
-------------------------------
mid tid mname
-------------------------------
m1 t1 billa
m2 t1 kalluri
m3 t2 pidichirukku
m4 t2 jodha akbar
---------------------------------

The coding I have given is as follows

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim str, str1 As String
Str = "user id=sa;password=;data source=AURO-RA4;initial catalog=suganya;server=AURO-RA4"
con = New SqlConnection(str)
Try
con.Open()
Catch
End Try
str1 = "SELECT mname FROM movie WHERE tid = (SELECT tid FROM theater WHERE tname = '" & DropDownList2.SelectedValue & "'"
cmd = New SqlCommand(str1, con)
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteReader()
DropDownList3.Items.Clear()
While dr1.Read()
DropDownList3.Items.Add(dr1.GetValue(0).ToString() )
End While
con.Close()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim str, str1 As String
str = "user id=sa;password=;data source=AURO-RA4;initial catalog=suganya;server=AURO-RA4"
con = New SqlConnection(str)
Try
con.Open()
Catch
End Try
str1 = "select tname,tid from theater"
cmd = New SqlCommand(str1, con)
Dim dr2 As SqlDataReader
dr2 = cmd.ExecuteReader()

While dr2.Read()
DropDownList2.Items.Add(dr2.GetValue(0).ToString() )

End While
End If
End Sub

ERROR:
Line 1: Incorrect syntax near 'cinipriya'.
Line 1: Incorrect syntax near 'devi'.

The error is on the line:-------Line 23: dr1 = cmd.ExecuteReader()

-sweatha
Mar 20 '08 #1
3 743
malav123
217 100+
Dear Friends

This is Sweatha. Right now I am working in the ASP.NET 2005 with VB coding & the back end is SQL SERVER 2000.

My dilemma is

I have to design a form with 2 DropDownListboxes. I have to load the ‘names of the theater’ on the 1st DropDownListbox & the names of the movie on the second DropDownListbox. That’s why I have created 2 tables named ‘theater’ and ‘movie’ on sql server 2000. The ‘theater’ table consists of 2 fields

Table Name: Theater
-------------------
tid tname
--------------------
t1 udhayam
t2 devi
t3 cinipriya
t4 dhanam
t5 pallavi
--------------------
The 'movie' table has 2 fields

Table Name
-------------------------------
mid tid mname
-------------------------------
m1 t1 billa
m2 t1 kalluri
m3 t2 pidichirukku
m4 t2 jodha akbar
---------------------------------

The coding I have given is as follows

Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim str, str1 As String
Str = "user id=sa;password=;data source=AURO-RA4;initial catalog=suganya;server=AURO-RA4"
con = New SqlConnection(str)
Try
con.Open()
Catch
End Try
str1 = "SELECT mname FROM movie WHERE tid = (SELECT tid FROM theater WHERE tname = '" & DropDownList2.SelectedValue & "'"
cmd = New SqlCommand(str1, con)
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteReader()
DropDownList3.Items.Clear()
While dr1.Read()
DropDownList3.Items.Add(dr1.GetValue(0).ToString() )
End While
con.Close()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim str, str1 As String
str = "user id=sa;password=;data source=AURO-RA4;initial catalog=suganya;server=AURO-RA4"
con = New SqlConnection(str)
Try
con.Open()
Catch
End Try
str1 = "select tname,tid from theater"
cmd = New SqlCommand(str1, con)
Dim dr2 As SqlDataReader
dr2 = cmd.ExecuteReader()

While dr2.Read()
DropDownList2.Items.Add(dr2.GetValue(0).ToString() )

End While
End If
End Sub

ERROR:
Line 1: Incorrect syntax near 'cinipriya'.
Line 1: Incorrect syntax near 'devi'.

The error is on the line:-------Line 23: dr1 = cmd.ExecuteReader()

-sweatha




Please send me proper Error.... I think Error should be in your sqldatareader...
Mar 20 '08 #2
sweatha
44
ERROR IS

Server Error in '/WebSite2' Application.
Line 1: Incorrect syntax near 'devi'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'devi'.

Source Error:

Line 22: Dim dr1 As SqlDataReader
Line 23:
Line 24: dr1 = cmd.ExecuteReader()
Line 25:
Line 26: While dr1.Read()


Source File: C:\Documents and Settings\SMART\My Documents\Visual Studio 2005\WebSites\WebSite2\Default3.aspx.vb Line: 24
Mar 20 '08 #3
malav123
217 100+
ERROR IS

Server Error in '/WebSite2' Application.
Line 1: Incorrect syntax near 'devi'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'devi'.

Source Error:

Line 22: Dim dr1 As SqlDataReader
Line 23:
Line 24: dr1 = cmd.ExecuteReader()
Line 25:
Line 26: While dr1.Read()


Source File: C:\Documents and Settings\SMART\My Documents\Visual Studio 2005\WebSites\WebSite2\Default3.aspx.vb Line: 24




Hi Swetha,
First of all Check your syntax in "str1" there is syntax error that there is no closing bracket is available... and if then also if u will get error then check your database that you have given proper datatype or not ???
I think there is syntax error only....
so first of all check out syntax of whole code...
your problem will be solved....
Mar 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
4
by: VB Programmer | last post by:
I have a function that returns a datareader. The problem is that in the function's FINALLY I close the datareader and set it to nothing. But, BEFORE the Finally I "Return" the datareader (in the...
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
17
by: Alan Silver | last post by:
Hello, I have a generic method in a utility class that grabs an sqldatareader and returns it. Due to the fact that (AFAIK), you can't close the database connection before you've read the data,...
3
by: Carlos Lozano | last post by:
Hello, I am having a problem getting the selectedValue from a dropdownlist that is populated with a dataReader and just can't see the problem. I did the following: dim dr as DataReader dr...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
1
by: Steve | last post by:
Hi, I currently display all the data on a website using tableadaptors and objectdatasources. Would it be significantly faster if I was to display the data by writing the code for a datareader...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.