Dim connection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
Dim conn As New SqlConnection(connection)
conn.Open()
Dim comm As String = "INSERT INTO GUES(GUES_NAME,GNDR,NATN,IDEN,E_MAIL,ADDR,TELP_NO)"
comm &= "VALUES('" & TextBox1.Text & "',"
comm &= "'" & TextBox2.Text & "',"
comm &= "'" & TextBox3.Text & "',"
comm &= "'" & TextBox4.Text & "',"
comm &= "'" & TextBox5.Text & "',"
comm &= "'" & TextBox6.Text & "',"
comm &= "'" & TextBox7.Text & "')"
Dim command As New SqlCommand(comm, conn)
command.ExecuteNonQuery()
comm = ("select top 1 GUES_ID from GUES ")
command = New SqlCommand(comm, conn)
Dim reader As SqlDataReader = command.ExecuteReader()
reader.Read()
Dim Personalid As Integer = reader("GUES_ID")
reader.Close()
comm = "INSERT INTO RESV(GUES_ID,ROOM_ID,DATE_FROM,DATE_TO,RESV_STTS,DATE_RESV)"
comm &= "VALUES('" & Personalid & "',"
comm &= "'" & lblSeleceRoom.Text & "',"
comm &= "Convert(DateTime, '" & lblSeleceDate.Text & "', 103),"
comm &= "Convert(DateTime, '" & lblSeleceDate1.Text & "', 103),"
comm &= "'A',"
comm &= "'" & DateNow & "')"
Dim acommand As New SqlCommand(comm, conn)
acommand.ExecuteNonQuery()
conn.Close()
End Sub
End Class
code2 Code (VB.NET)
Dim connection As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
Dim conn As New SqlConnection(connection)
conn.Open()
Dim comm As String = "INSERT INTO GUES(GUES_NAME,GNDR,NATN,IDEN,E_MAIL,ADDR,TELP_NO)"
comm &= "VALUES('" & TextBox1.Text & "',"
comm &= "'" & TextBox2.Text & "',"
comm &= "'" & TextBox3.Text & "',"
comm &= "'" & TextBox4.Text & "',"
comm &= "'" & TextBox5.Text & "',"
comm &= "'" & TextBox6.Text & "',"
comm &= "'" & TextBox7.Text & "')"
Dim command As New SqlCommand(comm, conn)
command.ExecuteNonQuery()
comm = ("SELECT MAX(GUES_ID) AS MaxGUES_ID FROM GUES")
command = New SqlCommand(comm, conn)
Dim reader As SqlDataReader = command.ExecuteReader()
reader.Read()
Dim Personalid As Integer = reader("GUES_ID")
reader.Close()
comm = "INSERT INTO RESV(GUES_ID,ROOM_ID,DATE_FROM,DATE_TO,RESV_STTS,DATE_RESV)"
comm &= "VALUES('" & Personalid & "',"
comm &= "'" & lblSeleceRoom.Text & "',"
comm &= "Convert(DateTime, '" & lblSeleceDate.Text & "', 103),"
comm &= "Convert(DateTime, '" & lblSeleceDate1.Text & "', 103),"
comm &= "'A',"
comm &= "'" & DateNow & "')"
Dim acommand As New SqlCommand(comm, conn)
acommand.ExecuteNonQuery()
conn.Close()
End Sub
End Class