0

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

Edited by mike_2000_17: Fixed formatting

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by binoj_daniel
0

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

0

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


}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.