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.SqlC
onnection con =
new System.Data.SqlClient.SqlC
onnection(
@"Data Source=.\sqlexpress;Attach
DbFilename
=|DataDire
ctory|\Mai
nDB.mdf;In
tegrated Security=True;User Instance=True");
//Create new data adapter and perform query
System.Data.SqlClient.SqlD
ataAdapter
da = new System.Data.SqlClient.SqlD
ataAdapter
(
"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
Lee
Start Free Trial