Dear Sir,

SQL SERVER 2005, Table1 has data as follows

Date----------sno----------name
14/01/10------1-------------A
14/01/10------2-------------B
14/01/10------3-------------C

The Primary key is on SNO

I want to apply primary key on sno+date columns

I want to enter sno on daily basis as
14/01/10------1-------------A
14/01/10------2-------------S
15/01/10------1-------------D
15/01/10------2-------------U

I want to use these codes before inserting data

str = "Select * from Table where sno= " & Val(Me.txtsno.Text) & " And Date =  " & Me.txtDat.Text
        dt = GetTable(str)

        If (dt.Rows.Count = 0) Then
            Dim cmd As New SqlClient.SqlCommand("Insert Into Table1 (date,sno,name) Values (@sno,@date, @name)", con)

            cmd.Parameters.AddWithValue("@sno", IIf(Val(Me.txtsno.Text) = 0, " ", Val(Me.txtsno.Text)))
            cmd.Parameters.AddWithValue("@date", IIf(Len(Me.txtDat.Text) = 0, " ", (Me.txtDat.Text)))
            cmd.Parameters.AddWithValue("@name", IIf(Len(Me.txtname.Text) = 0, " ", (Me.txtname.Text)))
            cmd.ExecuteNonQuery()
        Else
            MsgBox("Record already exists !! ", MsgBoxStyle.Information)
        End If

Please(Help)

>I want to apply primary key on sno+date columns
Yes. It is called composite-primary key.

Note: You can't assign blanks (spaces) to date and numeric fields.

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.