Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I m developing a windows form trying to connect front end with back end (SQL).I had given name space to get sql connection
C#
using System.Data;

C#
using System.Data.SqlClient;

but in run time it is showing error that the name space is not correct . what should I do for name space please help?



Thanks & Regards
Indrajit
Posted

That should work, if you are developing a WinForms project.

using System.data.SqlClient;
should then allow you to enter SqlCommand objects.

Try this:
If your code, find a random method and enter a new line.
On that line, type "SqlCommand" without the double quote characters.
When you type the "d" at the end, a small red outlined bar should appear under it.
Move the mouse over the bar. A small drop down should appear.
Open the drop down. Your should have two options: "using System.Data.SqlClient" and "System.Data.SqlClient.SqlCommand".
Select the "using" one - this should insert the appropriate using statement for you, and the SqlCommand should turn light blue.

If it doesn't happen like this, at which stage does it behave differently?
 
Share this answer
 
for Vb you need to write

VB
Imports System.data
Imports System.data.Sqlclient
 
Share this answer
 
Your using C# statements in VB.NET you need to change it too

Imports System.Data
Imports System.data.sqlclient


If it still gives you an error then you will need to create a reference to system.data.sqlclient.
 
Share this answer
 
using System.Data;
using System.Data.SqlClient;
//----------------------------------
string connecttionstring = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
            SqlConnection cs1 = new SqlConnection(connecttionstring);
            SqlCommand cmd1 = new SqlCommand();
            cs1.Open();
            cmd1.CommandText = "Select * from PrintTypes";
            cmd1.Connection = cs1;
            DataSet dtst = new DataSet();
            SqlDataAdapter dp = new SqlDataAdapter(cmd1);
            dp.Fill(dtst);// for select query
            cs1.Close();

//where connection strin can be set in the app.config or given directly to new //SqlConnection(connecttionstring)
 
Share this answer
 
v2
Comments
Toniyo Jackson 11-Apr-11 5:31am    
Use pre tag for code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900