C# with Visual Studio 2008
Hey guyz,can somebody help me how to connect to my database,i'm using SQL Server 2005. my OS is Vista..tnkssss...
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hirendra SisodiyaPosted Mar 19, 2010, 1:32 AM
you can connect sql server database through simple query, can you tell me what is problem.????
you can use this connection string:
Data source=Server_Name;Initial Catalog=DataBase_Name;Integrated Security=True;
you can also try to connect using SQL Server authentication :
Data Source=Server_Name;User ID=USER_ID;Password=PWD;Initial Catalog=DataBase_Name;
make sure all the information about your database name and server name should be correct
if you have any problem let me know
thanks
mark as answere if you like my answere
Sam HobbsPosted Mar 19, 2010, 4:24 PM
Felix CalvoPosted Mar 19, 2010, 2:19 AM
Sailaja YPosted Mar 19, 2010, 2:07 AM
After including the connection string as mentioned in the above post.
In the code, create a SQLCommand object and SqlConnection object.
Using the SqlCommand object u can assign the query to fetch the data from the database.
To add the data to the database,
connString = "Data Source=Server_Name;User ID=USER_ID;Password=PWD;Initial Catalog=DataBase_Name;";
cmdStrng = "Insert into table_Name Values ( '" + input1+ "' ,'" + input2+ "' ");
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = connString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = cmdStrng;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConn;
sqlConnOpen();
int result = (int)cmd.ExecuteNonQuery();
sqlConn.Close();
Try this code to add the values to database tables.
Mark it as answer if this helped u.
Felix CalvoPosted Mar 19, 2010, 1:42 AM
tnx a lot 4 d reply...