473,386 Members | 1,908 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,386 software developers and data experts.

ExecuteReader

Hi,

In Visual studio 2008, i got a error "ExecuteReader: Connection property has not been initialized" . So guide me

Expand|Select|Wrap|Line Numbers
  1.  protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         string constr=ConfigurationSettings.AppSettings["Myconn"];
  4.         SqlConnection conn = new SqlConnection(constr);
  5.         conn.Open();
  6.         SqlCommand cmd = new SqlCommand();
  7.         cmd.CommandText = "select * from users where username='" + txtusername.Text + "' and user_password='" + txtpassword.Text + "'";
  8.         SqlDataReader rd = cmd.ExecuteReader();
  9.  
  10.             if (rd.HasRows == true)
  11.             {
  12.                 Response.Redirect("Index.aspx");
  13.             }
  14.  
  15.         conn.Close();
  16.  
  17.     }
Apr 30 '08 #1
2 1942
vee10
141 100+
Hi,
u should initialize the connection property of the sqlcommand variable

Expand|Select|Wrap|Line Numbers
  1.  
  2. cmd .Connection = conn;
  3.  
  4.  

Hi,

In Visual studio 2008, i got a error "ExecuteReader: Connection property has not been initialized" . So guide me


protected void Button1_Click(object sender, EventArgs e)
{
string constr=ConfigurationSettings.AppSettings["Myconn"];
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from users where username='" + txtusername.Text + "' and user_password='" + txtpassword.Text + "'";
SqlDataReader rd = cmd.ExecuteReader();

if (rd.HasRows == true)
{
Response.Redirect("Index.aspx");
}

conn.Close();

}
Apr 30 '08 #2
Plater
7,872 Expert 4TB
You need to associate the command object with the connection object.
I believe it can be done in the constructor as well as setting a property.
Apr 30 '08 #3

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

Similar topics

0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
6
by: BuddyWork | last post by:
Does anyone know if there are any articles explaining how I could debug into SqlCommand.ExecuteReader so I can see why I am getting a particular error. thanks
0
by: BuddyWork | last post by:
Hello, The problem is that when using SqlCommand.ExecuteReader and the SQL statement raises an error of severity of 16 then ExecuteReader throws an exception, when you use...
5
by: orencs | last post by:
Hello, I am using Microsoft.Practices.EnterpriseLibrary.Data. I am running the following sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT var3 FROM table2 WHERE var2 IN...
2
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated...
4
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
5
by: Robert Bravery | last post by:
HI all, Whats the differe between useing Executereader() and Beginexecutereader()...endexecutereader() for asyncronys running of a SP Thanks Robert
1
by: fniles | last post by:
I am using OLEDBDataReader to read from an Access database. I have 4 data source where I get my data from, and each data source is in its own thread. When receiving data, if it is a new...
7
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.