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
Please Help
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
VB.NET:
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