Connecting Tech Pros Worldwide Forums | Help | Site Map

Connecting to a SQL Server 2005 (Express Edition) database

=?Utf-8?B?U2hlcndvb2Q=?=
Guest
 
Posts: n/a
#1: Jun 27 '08
Greetings,

I am using Visual C#.NET 2005 (Express Edtion) and want to retrieve data
from a SQL Server 2005 (Express Edition) database. However, I see that there
is no SQL Data Adapter control nor a SQL Connection control. What controls
should I use instead?

Thanks in advance!

=?Utf-8?B?TXVkYXNzYXIgSGFzc2Fu?=
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Connecting to a SQL Server 2005 (Express Edition) database


You can connect to sql server using the code.

1. First create connection object and give it a connectionstring

System.Data.SqlClient.SqlConnection con;
con.ConnectionString = "Data Source=yourservername;Initial
Catalog=yourdbname;User ID=sa";
con.Open();

2. Now you can use retrieve data from database using sqldataReader object or
SQLDataAdapter Object through SQLCOmmand like

System.Data.SqlClient.SqlCommand sql;
sql.CommandText = "SELECT * FROM emp";
sql.Connection = con;

string empname;
System.Data.SqlClient.SqlDataReader rd;
rd = sql.ExecuteReader;
while (rd.Read=true)
{
empname = rd("columnname");
}
rd.Close;



"Sherwood" wrote:
Quote:
Greetings,
>
I am using Visual C#.NET 2005 (Express Edtion) and want to retrieve data
from a SQL Server 2005 (Express Edition) database. However, I see that there
is no SQL Data Adapter control nor a SQL Connection control. What controls
should I use instead?
>
Thanks in advance!
=?Utf-8?B?U2hlcndvb2Q=?=
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Connecting to a SQL Server 2005 (Express Edition) database


Thanks. However, I tried compiling this code and received the following error:

"Cannot convert method group 'ExecuteReader' to non-delegate type
'System.Data.SqlClient.SqlDataReader'. Did you intend to invoke the method?"

This error occurs on the following line of code:
rd = sql.ExecuteReader;

Any ideas?

Thanks!

"Mudassar Hassan" wrote:
Quote:
You can connect to sql server using the code.
>
1. First create connection object and give it a connectionstring
>
System.Data.SqlClient.SqlConnection con;
con.ConnectionString = "Data Source=yourservername;Initial
Catalog=yourdbname;User ID=sa";
con.Open();
>
2. Now you can use retrieve data from database using sqldataReader object or
SQLDataAdapter Object through SQLCOmmand like
>
System.Data.SqlClient.SqlCommand sql;
sql.CommandText = "SELECT * FROM emp";
sql.Connection = con;
>
string empname;
System.Data.SqlClient.SqlDataReader rd;
rd = sql.ExecuteReader;
while (rd.Read=true)
{
empname = rd("columnname");
}
rd.Close;
>
>
>
"Sherwood" wrote:
>
Quote:
Greetings,

I am using Visual C#.NET 2005 (Express Edtion) and want to retrieve data
from a SQL Server 2005 (Express Edition) database. However, I see that there
is no SQL Data Adapter control nor a SQL Connection control. What controls
should I use instead?

Thanks in advance!
Chris Jobson
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Connecting to a SQL Server 2005 (Express Edition) database


Thanks. However, I tried compiling this code and received the following
Quote:
error:
>
"Cannot convert method group 'ExecuteReader' to non-delegate type
'System.Data.SqlClient.SqlDataReader'. Did you intend to invoke the
method?"
>
This error occurs on the following line of code:
rd = sql.ExecuteReader;
I suspect the line should be:
rd = sql.ExecuteReader();

Chris Jobson


Closed Thread