Here's my code...there's just something that doesn't work. Right now I'm getting an error in the data bind about an open connection! Thanks in advance for the help!
<%@ Page Title="" Language="VB" MasterPageFile="admin.master" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
BindData()
End Sub
Sub BindData()
Const sConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sheetalk\Documents\Database3.accdb"
Dim objConn As New OleDbConnection(sConnStr)
objConn.Open()
Const strSQL As String = "SELECT Show_ID, Show_Name FROM Shows Order By Show_Name"
Dim objCmd As New OleDbCommand(strSQL, objConn)
'Create/Populate the DataReader
'Dim objDR As OleDbDataReader
objDR = objCmd.ExecuteReader()
Showslistbox.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Showslistbox.DataBind()
End Sub
Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim conCoaxis As OleDbConnection
Dim result As Integer = 0
Dim pickvalue As String = Showslistbox.SelectedItem.Value
Dim i As Integer = Convert.ToInt16(pickvalue)
Dim strSelect As String
Dim strInsert As String
Dim cmdSelect As OleDbCommand
Dim cmdInsert As OleDbCommand
conCoaxis = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sheetalk\Documents\Database3.accdb")
strSelect = "Select ID from Users WHERE Username = '" & Session("User") & "'"
cmdSelect = New OleDbCommand(strSelect, conCoaxis)
strInsert = "INSERT into Affidavits (show_id, affidavit_air_date, affidavit_air_time, user_id) Values (@showid, @affDate, @affTime," & result & ")"
cmdInsert = New OleDbCommand(strInsert, conCoaxis)
cmdInsert.Parameters.AddWithValue("@affDate", affDate.Text)
cmdInsert.Parameters.AddWithValue("@affTime", affTime.Text)
cmdInsert.Parameters.AddWithValue("@showid", i)
conCoaxis.Open()
result = DirectCast(cmdSelect.ExecuteScalar(), Integer)
cmdInsert.ExecuteNonQuery()
conCoaxis.Close()
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="cphhead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" Runat="Server">
<h1>Affidavit</h1>
<table>
<tr>
<td>Shows: </td>
<td><asp:ListBox ID="Showslistbox" runat="server" Rows="1" DataTextField="Show_Name" Datavaluefield="Show_ID" /></td>
</tr>
<tr>
<td>Time: </td>
<td><asp:TextBox ID="affTime" runat="server"/>
<asp:RequiredFieldValidator ID="affTimereq" ControlToValidate="affTime" ErrorMessage="Required" Display="Dynamic" runat="server" /></td>
</tr>
<tr>
<td>Date: </td>
<td><asp:TextBox ID="affDate" runat="server" />
<asp:RequiredFieldValidator ID="affDatereq" ControlToValidate="affDate" ErrorMessage="Required" Display="Dynamic" runat="server" /></td>
</tr>
<tr><td><asp:Button ID="Submit" runat="server" text="Submit" OnClick="Submit_click" /></td></tr>
</table>
</asp:Content>
<%@ Page Title="" Language="VB" MasterPageFile="admin.master" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
BindData()
End Sub
Sub BindData()
Const sConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sheetalk\Documents\Database3.accdb"
Dim objConn As New OleDbConnection(sConnStr)
objConn.Open()
Const strSQL As String = "SELECT Show_ID, Show_Name FROM Shows Order By Show_Name"
Dim objCmd As New OleDbCommand(strSQL, objConn)
'Create/Populate the DataReader
'Dim objDR As OleDbDataReader
objDR = objCmd.ExecuteReader()
Showslistbox.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Showslistbox.DataBind()
End Sub
Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim conCoaxis As OleDbConnection
Dim result As Integer = 0
Dim pickvalue As String = Showslistbox.SelectedItem.Value
Dim i As Integer = Convert.ToInt16(pickvalue)
Dim strSelect As String
Dim strInsert As String
Dim cmdSelect As OleDbCommand
Dim cmdInsert As OleDbCommand
conCoaxis = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sheetalk\Documents\Database3.accdb")
strSelect = "Select ID from Users WHERE Username = '" & Session("User") & "'"
cmdSelect = New OleDbCommand(strSelect, conCoaxis)
strInsert = "INSERT into Affidavits (show_id, affidavit_air_date, affidavit_air_time, user_id) Values (@showid, @affDate, @affTime," & result & ")"
cmdInsert = New OleDbCommand(strInsert, conCoaxis)
cmdInsert.Parameters.AddWithValue("@affDate", affDate.Text)
cmdInsert.Parameters.AddWithValue("@affTime", affTime.Text)
cmdInsert.Parameters.AddWithValue("@showid", i)
conCoaxis.Open()
result = DirectCast(cmdSelect.ExecuteScalar(), Integer)
cmdInsert.ExecuteNonQuery()
conCoaxis.Close()
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="cphhead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" Runat="Server">
<h1>Affidavit</h1>
<table>
<tr>
<td>Shows: </td>
<td><asp:ListBox ID="Showslistbox" runat="server" Rows="1" DataTextField="Show_Name" Datavaluefield="Show_ID" /></td>
</tr>
<tr>
<td>Time: </td>
<td><asp:TextBox ID="affTime" runat="server"/>
<asp:RequiredFieldValidator ID="affTimereq" ControlToValidate="affTime" ErrorMessage="Required" Display="Dynamic" runat="server" /></td>
</tr>
<tr>
<td>Date: </td>
<td><asp:TextBox ID="affDate" runat="server" />
<asp:RequiredFieldValidator ID="affDatereq" ControlToValidate="affDate" ErrorMessage="Required" Display="Dynamic" runat="server" /></td>
</tr>
<tr><td><asp:Button ID="Submit" runat="server" text="Submit" OnClick="Submit_click" /></td></tr>
</table>
</asp:Content>