Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Insert a record in C# 2003

Author  Topic 

haibec
Yak Posting Veteran

54 Posts

Posted - 2008-01-17 : 12:32:26
Hi all!
I have a table customer: ID,Name,Age. Please help me scirpt (Full) insert a new record into my table

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-01-17 : 12:38:20
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson03.aspx


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

SNK111
Starting Member

1 Post

Posted - 2010-09-02 : 01:07:45
To connect to SQL Server, you need to create a connection string such as below:

private SqlConnection connection;
private string connectionString =
@"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123";
connection = new SqlConnection( connectionString );

Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:
SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);

The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.

Next to execute the SQL queries in the database, you use the following methods:
ExecuteReader - to execute SELECT queries
ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.

This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database.
For details about the connection string, the methods and their parameters check the following link: ( http://www.shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html )
Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.[url][/url]
Go to Top of Page
   

- Advertisement -