C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Connectivity of SQL to C#


Posted Date: 16 Sep 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: anil momin       Member Level: Silver
Rating:     Points: 10




private void Save_Click(object sender, EventArgs e)
{
//******* For database using SQL EXPRESS ***********

string conString = @"Initial Catalog=database_name;" +
@"Data Source=.\SQLEXPRESS;"+
@"AttachDbFilename=\database_name.mdf;"+
@"Integrated Security=True;"+
@"User Instance=True;";


//******* For Database with SQL Server 2005 installed seperatly********

/* string conString = @"Initial Catalog=bookdata;" +
@"Data Source=computername\SQLEXPRESS;"+
@"Integrated Security=True;" */


SqlConnection connection = new SqlConnection(conString);

connection.Open();
String MyString = "INSERT INTO bookentry (AuthorName, BookTitle, Price) VALUES('"+ textBox2.Text+"' ,'"+ textBox3.Text+"' ,'"+ textBox4.Text +"' );";

SqlCommand command = new SqlCommand(MyString,connection);
command.ExecuteNonQuery();
connection.Close();

label1.Text = "Successfull";

}


The above code is for a button event on clicking the button the information for textboxes are stored in the database residing on other server if you are using SQL Express then use the connection String mentioned seperately




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  

Connectivity of SQL to C#

  .  


Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to Create Relations in Data Set using ADO.NET
Previous Resource: C# code to check the table is exists in the oracle database
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use