hi,

i am trying to create a database driven application using Sql2005 and c#.. i have alittle problem

can anyone tell me how to connect to sql database using c# and do simple transactions such as insert update delete and search ...but it shud be fully code based.

if possible please provide a sample.....

but it shud be fully code based.

Friend, if you search on MSDN you'll find a lot of articles there. and you can post here specific question say, when you connect on SQL Server your application releases exception lmlmlma, so the question is "what's the error, friends..."
Best of luck with http://msdn.com

hi,

i am trying to create a database driven application using Sql2005 and c#.. i have alittle problem

can anyone tell me how to connect to sql database using c# and do simple transactions such as insert update delete and search ...but it shud be fully code based.

if possible please provide a sample.....

hi dear nish here

listen with first create database in sql with
create database command
-------------------
after dat when u r writing code in ur .net window
create connection then
open the connection
create command()
set the command type property(in this u have to write select ,insert,delete stt whatever u want)
at last if u want to read something then make datareader object and specify the columns which u made in the sql table
or if uwant to insert ,delete or update something then
simply write---
command object which u made above.execute nonquery
dats it

hi,

i am trying to create a database driven application using Sql2005 and c#.. i have alittle problem

can anyone tell me how to connect to sql database using c# and do simple transactions such as insert update delete and search ...but it shud be fully code based.

if possible please provide a sample.....

Hi,

First add Using System.SqlClient; namespace to your cs file.

Then write connection string like this

//Connection String
SqlConnection conn = new SqlConnection("data source=<NameOfYourSqlServerInstance>;Initial catalog=<NameOfYourDataBase>; username = <UserName>; password =<Password>;Integrated Security=True");

//Insert Method
SqlConnection conn = new SqlConnection("data source=<NameOfYourSqlServerInstance>;Initial catalog=<NameOfYourDataBase>; username = <UserName>; password =<Password>;Integrated Security=True");
SqlCommand cmd = new SqlCommand("InsertQuery",conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

//Update Method
SqlConnection conn = new SqlConnection("data source=<NameOfYourSqlServerInstance>;Initial catalog=<NameOfYourDataBase>; username = <UserName>; password =<Password>;Integrated Security=True");
SqlCommand cmd = new SqlCommand("UpdateQuery",conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

//Delete Method
SqlConnection conn = new SqlConnection("data source=<NameOfYourSqlServerInstance>;Initial catalog=<NameOfYourDataBase>; username = <UserName>; password =<Password>;Integrated Security=True");
SqlCommand cmd = new SqlCommand("DeleteQuery",conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

This article has been dead for over six months. Start a new discussion instead.