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

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
)

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?

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.