0

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)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

>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.

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.