Advertisement

12.31.2007 at 06:43AM PST, ID: 23050725
[x]
Attachment Details

how to insert a record into ms sql database in c# using visual studio 2005

Asked by ljhodgett in Microsoft Visual C#.Net, ADO.Net Class Library

Tags: insert, sql, database, using, record

Hi,

I am trying to find out how to execute the following sql statment to my ms sql database in c# winforms using visual studio 2005: -

INSERT INTO Users Values (NewID(), 'Eljay', 'c:\pics\pic1.jpg', 'c:\pics\pic2.jpg')

I have the following code that queries the database that shows the connection string I am using: -
  //Create new virtual dataset
            DataSet yds = new DataSet();

            //Create connection to mdf sql file
            System.Data.SqlClient.SqlConnection con =
                new System.Data.SqlClient.SqlConnection(
                @"Data Source=.\sqlexpress;AttachDbFilename=|DataDirectory|\MainDB.mdf;Integrated Security=True;User Instance=True");
           
            //Create new data adapter and perform query
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(
                "Select * from users order by Username", con.ConnectionString);
           
            // place result into virtual dataset yds
            da.Fill(yds);

            //Bind virtual dataset yds to combobox and display username but value is the userID index
            cmbUsers.DisplayMember = "Username";
            cmbUsers.ValueMember = "UserID";
            cmbUsers.DataSource = yds.Tables[0];

Many thanks
LeeStart Free Trial
[+][-]12.31.2007 at 07:20AM PST, ID: 20555289

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, ADO.Net Class Library
Tags: insert, sql, database, using, record
Sign Up Now!
Solution Provided By: sjturner2
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12.31.2007 at 07:51AM PST, ID: 20555563

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.31.2007 at 08:06AM PST, ID: 20555689

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2007 at 08:57AM PST, ID: 20556082

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.31.2007 at 09:35AM PST, ID: 20556342

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2007 at 10:13AM PST, ID: 20556544

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.31.2007 at 10:29AM PST, ID: 20556645

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2007 at 10:30AM PST, ID: 20556655

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628