I have a dropdown list named ddllst. I want to save the ID in tblLogentry. How do do this? I know there is a problem with my code:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class logentry
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim connectionstring = WebConfigurationManager.ConnectionStrings("LMConnectionString").ConnectionString
Dim AddSQL As String
AddSQL = "INSERT INTO tblLogBook (techInit,timeIn,date_submit,time_submit,entry,areaID)VALUES("
AddSQL &= "'" & Me.txtInit.Text & "',"
AddSQL &= "'" & Now.Date.ToString & "', "
AddSQL &= "'" & Me.txtCurrDate.Text & "',"
AddSQL &= "'" & Me.txtCurrTime.Text & "',"
AddSQL &= "'" & Me.txtEntry.Text & "',"
AddSQL &= "'" & Me.ddlLst.UniqueID & "')"
Dim con As New SqlConnection(connectionstring)
Dim cmd As New SqlCommand(AddSQL, con)
Dim added As Integer = 0
Try
con.Open()
added = cmd.ExecuteNonQuery()
Me.lblResults.Text = added.ToString() & "Records Inserted"
Catch ex As Exception
Me.lblResults.Text = "Error inserting record"
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not (Page.IsPostBack) Then
Dim militaryTimeFormat As String = "HH:mm"
Me.txtCurrDate.Text = String.Format("{0:d}", Now())
Me.txtCurrTime.Text = DateTime.Now.ToString(militaryTimeFormat)
Me.ddlLst.DataTextField = "area"
Me.ddlLst.DataValueField = "areaID"
End If
End Sub
End Class
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class logentry
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim connectionstring = WebConfigurationManager.ConnectionStrings("LMConnectionString").ConnectionString
Dim AddSQL As String
AddSQL = "INSERT INTO tblLogBook (techInit,timeIn,date_submit,time_submit,entry,areaID)VALUES("
AddSQL &= "'" & Me.txtInit.Text & "',"
AddSQL &= "'" & Now.Date.ToString & "', "
AddSQL &= "'" & Me.txtCurrDate.Text & "',"
AddSQL &= "'" & Me.txtCurrTime.Text & "',"
AddSQL &= "'" & Me.txtEntry.Text & "',"
AddSQL &= "'" & Me.ddlLst.UniqueID & "')"
Dim con As New SqlConnection(connectionstring)
Dim cmd As New SqlCommand(AddSQL, con)
Dim added As Integer = 0
Try
con.Open()
added = cmd.ExecuteNonQuery()
Me.lblResults.Text = added.ToString() & "Records Inserted"
Catch ex As Exception
Me.lblResults.Text = "Error inserting record"
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not (Page.IsPostBack) Then
Dim militaryTimeFormat As String = "HH:mm"
Me.txtCurrDate.Text = String.Format("{0:d}", Now())
Me.txtCurrTime.Text = DateTime.Now.ToString(militaryTimeFormat)
Me.ddlLst.DataTextField = "area"
Me.ddlLst.DataValueField = "areaID"
End If
End Sub
End Class