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

Problem with DataBinding

39
Hi

To bind a data from the DB in Labels I have given the coding as

public partial class SerachResult : System.Web.UI.Page
{
SqlConnection con;
SqlDataReader dr1;
string str;
string sql;
protected void Page_Load(object sender, EventArgs e)
{
this.Label1 .Text = Request.QueryString["Name"];
str = "user id=sa;password=cast;database=Hello_Dr;server=AUROR A-SERVER";
con= new SqlConnection(str);
con.Open();
sql = "SELECT * FROM DoctorRegistration3 where Name=" + Label1.Text + "";
SqlCommand cmd = new SqlCommand(sql, con);

dr1 = cmd.ExecuteReader();
while(dr1.Read())
{

Label3.Text = dr1.GetValue(14).ToString();
Label5.Text = dr1.GetValue(12).ToString();
Label7.Text = dr1.GetValue(13).ToString();
Label9.Text = dr1.GetValue(9).ToString();
Label11.Text = dr1.GetValue(10).ToString();
Label14.Text = dr1.GetValue(18).ToString();
Label15.Text = dr1.GetValue(19).ToString();
}

}}


But when I run the project, it shows the following error

SqlException was unhandled by user code:
Incorrect syntax near 'K'.

The error showing is on the line

dr1 = cmd.ExecuteReader();
Jun 18 '08 #1
3 799
r035198x
13,262 8TB
Use a try/catch to handle exceptions.
On your query you probably need to wrap the text in quotes so that it reads
Expand|Select|Wrap|Line Numbers
  1. where Name = 'K'
Something like
Expand|Select|Wrap|Line Numbers
  1. "where Name =  '"+text + "'" 
Jun 18 '08 #2
suganya
39
Use a try/catch to handle exceptions.
On your query you probably need to wrap the text in quotes so that it reads
Expand|Select|Wrap|Line Numbers
  1. where Name = 'K'
Something like
Expand|Select|Wrap|Line Numbers
  1. "where Name =  '"+text + "'" 


Thanks. Its working.
Jun 18 '08 #3
r035198x
13,262 8TB
Thanks. Its working.
Welcome, don't forget to handle potential exceptions using those try/catch blocks though.
Jun 18 '08 #4

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

Similar topics

2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
2
by: wolfgang wagner | last post by:
hi all! im trying to edit data in a datagrid (like described here: http://aspnet.4guysfromrolla.com/articles/071002-1.aspx) but if i click the edit button i get the following error invalid...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
2
by: Kalpesh | last post by:
Hello, I am facing a design problem here & need your expert design advice on this. Scenario: I have a class called Vendor - which has several simple attributes like Name, Address etc Now,...
1
by: m_mohanna | last post by:
I've problem with databinding in vb.net The problem that i'm trying to set a text field of the databinding programmatically during runtime, the change appears on the form, but after save the new...
7
by: Vlado Jasovic | last post by:
Hello, I'm using typed dataset for databinding to windows controls and I'm having some problems. I'm trying to move all business logic to datatable column_changing events and the problem that...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello to all, I want to know if DataBinding in asp.net 2,0 is better than to fill up the values of the controls of the following form: this.miControlTextBox.Text = valorParaControlTextbox; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.