.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Connect a new Database

Posted By:Shashi Ray       Posted Date: September 03, 2008    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

Connect a new Database sqlserver using ADO.Net. This sample code shows how to connect to a database

ADO.Net sample code using C#

private void submit_Click(object sender, System.EventArgs e)
SqlConnection con=new SqlConnection("Server=localhost;database=shashi;uid=sa;pwd=sa123");

string str="insert into shashi values '"+TextBox1.Text+"','"+textBox2.Text+"','"+TextBox3.Text+"', '"+TextBox4.Text+"','"+TextBox5.Text+"','"+DropDownList1.SelectedItem.Text+"','"+DropDownList2.SelectedItem+"')";

SqlCommand cmd=new SqlCommand(str,con);



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend