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

Recommended Answers

All 3 Replies

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

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


}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.