tags:

views:

36

answers:

3

I want to connect to SQL Server with ASP.NET. Can any one give me some sample program to do so?

+2  A: 

Here's an example

http://www.beansoftware.com/ASP.NET-Tutorials/ASP.NET-SQL-Server.aspx

Good Luck!

hgulyan
A: 

Simple example for this :-

More detail on link : http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson02.aspx

using System.Data;
using System.Data.SqlClient;

string Connection = "server=ALDAN; uid=sa; pwd=sa; database=GAZCAD; Connect Timeout=10000";

SqlConnection DataConnection = new SqlConnection(Connection);
// the string with T-SQL statement, pay attention: no semicolon at the end of //the statement
string Command = "INSERT INTO myTable VALUES (1,100)";
// create the SQLCommand instance
SQLCommand DataCommand = new SqlCommand(Command, DataConnection);
// open the connection with our database
DataCommand.Connection.Open();
// execute the statement and return the number of affected rows
int i = DataCommand.ExecuteNonQuery();
//close the connection
DataCommand.Connection.Close();
Pranay Rana
A: 

June R's example is inserting data.

using System.Data;
using System.Data.SqlClient;

string Connection = "server=ALDAN; uid=sa; pwd=sa; database=GAZCAD; Connect Timeout=10000";

SqlConnection DataConnection = new SqlConnection(Connection);
// the string with T-SQL statement, pay attention: no semicolon at the end of //the statement
string Command = "Select * from myTable";
// create the SQLCommand instance
SQLCommand DataCommand = new SqlCommand(Command, DataConnection);
// open the connection with our database
DataCommand.Connection.Open();
// Data adapter
SqlDataAdapter da = new SqlDataAdapter(DataCommand);
// To fill data, i need a datatable.
DataTable dt = new DataTable();
// Filling my table
da.Fill(dt);
bahadir arslan