Connecting to MSQL db

Newby Here

I am trying to set up a little form (on a Windows Form, using C#)

I am trying to work it out, so for testing I created on the Form.

2 TextBox's and a Button

What I want to happen, is someone types something in one text box, press submit, then the 2nd textbox will show the result from the MSQL table (mini Search Function)

So far I have

Added, under referenced System.Data.SqlClient

then on the top of the form1.cs page (Code Section)
I added

using System.Data.SqlClient


Then under the button_Click section

I added

System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("SERVER=localhost;DATABASE=test1;UID=username;PWD=dbpassword");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM tbl1 WHERE IDNum = '"+txtIdNum.Text+"', conn");
System.Data.DataSet ds = new System.Data.DataSet("MyDataset");
System.Data.SqlClient.SqlDataAdapter dbadapter = new System.Data.SqlClient.SqlDataAdapter(cmd, conn);

but I get errors on everything after SqlClient. (For example System.Data.SqlClient.SqlConnection conn = ....


The erorr is

Error 1 The type 'System.Data.SqlClient.SqlConnection' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll' and 'c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll' C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\TestSQL4\TestSQL4\Form1.cs

Any ideas.

(If you dont understand, please let me know)

Cheers in advance

Jamie


Answer this question

Connecting to MSQL db

  • Frederic Goulet

    Ahh, Thanks

    NOw..

    How do I get the field from the Table into the TextBox.

    I will add LIMIT 1, 0 to the query, to make sure, only one Row is shown.






  • AlanH99

    Post a thread for this question.

    Regards

    David



  • freibuis

    Remove the reference to System.Data.SqlClient.dll, this is used for the .NET Compact Framework.

  • Connecting to MSQL db