0

hi all ...i'am having a problem ..i'm working on an asp.net & silverlight project ....but the data base contain the (unique identifier) type ..and i don't know how to handles this type ...and also i can't add data to my data base coz this type is giving me alot of errors and it's not auto increment for an id ...plz help ....and thnx in advance

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by sknake
0
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace daniweb
{
  public partial class frmUniqueId : Form
  {
    public frmUniqueId()
    {
      InitializeComponent();
    }
    public static string BuildSqlNativeConnStr(string server, string database)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", server, database);
    }

    private void button1_Click(object sender, EventArgs e)
    {
      string connStr = BuildSqlNativeConnStr("apex2006sql", "Bugs");
      const string query = @"Insert Into Uniq (Col1) Values (@Col1)";
      using (SqlConnection conn = new SqlConnection(connStr))
      {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          cmd.Parameters.Add(new SqlParameter("@Col1", SqlDbType.UniqueIdentifier)).Value = Guid.NewGuid();
          cmd.ExecuteNonQuery();
        }
      }
    }
  }
}
Create Table Uniq
(
  Col1 uniqueidentifier
)
0

hi ...first of all thank you for you respond ..but i did not understand what u meant in your code ..and the major problem i'm having that when i declare the colonne as UI in the DB...coz i can't put data in the table manually ...and also i can't handle sql queries with the silverlight application coz i'm using RIA services ...soo what should i do?

0

Yes you can:

IF OBJECT_ID('Uniq', 'U') IS NOT NULL DROP TABLE Uniq
Create Table Uniq
(
  Col1 uniqueidentifier
)
GO
Insert Into Uniq (Col1) Values ( NewId() )
GO
Select * From Uniq
(1 row(s) affected)
Col1
------------------------------------
B6AF9F8F-9DC7-4A24-8812-DD60915123D4

(1 row(s) affected)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.