how to insert values to uniqueidentifier table in windows form
hi all ...i'am having a problem ..i'm working on an C#.net project ....but the data base Table contain the (unique identifier) type ..and i don't know how to insert the values from Windows form to database. this type ...and also i can't add data to my database coz this type is giving me alot of errors.2 TextBoxs and 1 Button Iam having in Windows Form.When iam entering the data and click OK button, data is saved but Uniquie Id shows NULL.Its Primary Key Column.it's not auto increment for an id ...plz help ....and thnx in advance
Kirtan PatelPosted Aug 28, 2009, 9:36 AM
you have used Select instead of set check out below one .
and dont forget to mark "Do you like answer please it will give me some credits :)
ALTER PROC AddNewSignature2 (@Description varchar(255), @UserID uniqueidentifier, @Signature text, @EmailAccountID varchar(100))
as
begin
DECLARE @GUID uniqueidentifier
set @GUID = newid()
INSERT SignatureTable (ID,Description,UserID,Signature)
SELECT @GUID,@Description, @UserID, @Signature
endroy himanshuPosted Aug 28, 2009, 9:21 AM
private void button1_Click(object sender, EventArgs e)
{
cmd.Parameters.Clear();
cmd.CommandText = "AddNewSignature2";
cmd .Parameters .AddWithValue ("@Description",textBox1 .Text );
cmd.Parameters.AddWithValue("@Signature", textBox2.Text);
cmd.Parameters.AddWithValue("@EmailAccountID", textBox4.Text);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
In STORE PROCEDURE
ALTER PROC AddNewSignature2 (@Description varchar(255), @UserID uniqueidentifier, @Signature text, @EmailAccountID varchar(100))
as
begin
DECLARE @GUID uniqueidentifier
SELECT @GUID = newid()
INSERT SignatureTable (ID,Description,UserID,Signature)
SELECT @GUID,@Description, @UserID, @Signature
end
plz solve my problem
Kirtan PatelPosted Aug 28, 2009, 8:42 AM
please post the code you are using
and Column name you have created in your database please so that i can resolve your problem quickly
roy himanshuPosted Aug 28, 2009, 8:33 AM
but now also iam getting error.
Kirtan PatelPosted Aug 28, 2009, 7:50 AM
If you Want to Automatically Generate GUID in Database then Use The Following Property of Column in SQL Server
it will generate GUID Automatically Like Auto number
Here is Another Solution if you want to generate Your Own Programatically :)
private void button1_Click(object sender, EventArgs e)
{
Guid id = Guid.NewGuid();
MessageBox.Show(id.ToString());
}