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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 18, 2010, 9:32 PM EDT
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
Felix Calvo16 reputationPosted Mar 18, 2010, 9:42 PM EDT
tnx a lot 4 d reply...
Sailaja Y37 reputationPosted Mar 18, 2010, 10:07 PM EDT
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 Calvo16 reputationPosted Mar 18, 2010, 10:19 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Mar 19, 2010, 12:24 PM EDT