Sql
Q.I want to save and retrive details to backend(Sql sever) by console C# programm please send me the code if possible thanks in advance....
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
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
Roei BarRank #1,271 · 1.4K reputationPosted Aug 14, 2009, 2:53 AM EDT
using (SqlConnection cn = new SqlConnection(connectionString)) { commandString ="INSERT INTO table (Column1, Column2) " + "Values ('string', 1)"); using (SqlCommand cm = new SqlCommand(commandString, cn)) { cn.Open(); cm.ExecuteNonQuery(); } }the select is :
using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); commandString ="select * from table"; using (SqlCommand cm = new SqlCommand(commandString, cn)) { using (SqlDataReader myReader = new SqlDataReader()) { myReader = cm .ExecuteReader(); while(myReader.Read()) { Console.WriteLine(myReader["Column1"].ToString()); Console.WriteLine(myReader["Column2"].ToString()); } } } }Rajat Uppal11 reputationPosted Aug 14, 2009, 2:54 AM EDT
Rajat Uppal11 reputationPosted Aug 14, 2009, 3:22 AM EDT