how to connect and querysql ASP.NET BY USING C# CODE

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 2
Reputation: eme2008 is an unknown quantity at this point 
Solved Threads: 0
eme2008 eme2008 is offline Offline
Newbie Poster

how to connect and querysql ASP.NET BY USING C# CODE

 
0
  #1
Mar 9th, 2008
Hello everyone,

I was wondering if anyone could tell me how to connect and query sql databases in ASP.NET
Using c # code
I try to use this code, but there is some mistake in the code lead to an error message

You must first withdraw from sqlDataadapter toolbar to connect to the structural language queries


using System.Data;

using System.Data.SqlClient;


{ string n1,n2,n3,n4;
n1=TextBox1.Text;
n2=TextBox2.Text;
n3=TextBox3.Text;
n4=TextBox4.Text;

Conn1.Open();
Adapter1.InsertCommand=new SqlCommand("Insert Into TEST1 Values('"+n1+"','"+n2+"','"+n3+"','"+n4+"')",Conn1);
Adapter1.InsertCommand.ExecuteNonQuery();
Conn1.Close();

}



Thank you in advance
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: eme2008 is an unknown quantity at this point 
Solved Threads: 0
eme2008 eme2008 is offline Offline
Newbie Poster

Re: how to connect and querysql ASP.NET BY USING C# CODE

 
0
  #2
Mar 9th, 2008
Hello everyone,

I was wondering if anyone could tell me how to connect and query sql databases in ASP.NET
Using c # code
I try to use this code, but there is some mistake in the code lead to an error message

You must first withdraw from sqlDataadapter toolbar to connect to the structural language queries


using System.Data;

using System.Data.SqlClient;


{ string n1,n2,n3,n4;
n1=TextBox1.Text;
n2=TextBox2.Text;
n3=TextBox3.Text;
n4=TextBox4.Text;

Conn1.Open();
Adapter1.InsertCommand=new SqlCommand("Insert Into TEST1 Values('"+n1+"','"+n2+"','"+n3+"','"+n4+"')",Conn1);
Adapter1.InsertCommand.ExecuteNonQuery();
Conn1.Close();

}



Thank you in advance
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1
Reputation: sagar.deshmukh is an unknown quantity at this point 
Solved Threads: 0
sagar.deshmukh sagar.deshmukh is offline Offline
Newbie Poster

Re: how to connect and querysql ASP.NET BY USING C# CODE

 
0
  #3
Mar 10th, 2008
I think you must try this code-----

using System.Data;
using System.Data.SqlClient;
{
string n1,n2,n3,n4;
n1=TextBox1.Text;
n2=TextBox2.Text;
n3=TextBox3.Text;
n4=TextBox4.Text;

string qr=Insert Into TEST1 Values('"+n1+"','"+n2+"','"+n3+"','"+n4+"')";

SqlConnection scon=new SqlConnection("server=your computername;uid=sa;pwd=sqlpassword;database=databasename");

SqlDataAdapter sda=new SqlDataAdapter(qr,scon);

DataSet ds=new DataSet();

sda.Fill(ds);

next to this bind it to your dataview or datagrid....

Hope this code will be helpfull


}
Last edited by sagar.deshmukh; Mar 10th, 2008 at 9:32 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: how to connect and querysql ASP.NET BY USING C# CODE

 
0
  #4
Mar 11th, 2008
You can read a VB.NET example here..

More ASP.NET Interview Questions
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC