Hi guys,
I am a newbie in asp and i have a problem.
I have a webpage that allow user to input their info in the webpage.
I am using stored procedure as the insert command in this webpage.
When a button is click, the data should go to the database but not.
This is the webapge code:
<asp:Content ID="Content1" ContentPlaceHolderID="StaffMainPageCPH" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table id="AppointmentTable" runat="server">
<tr>
<td colspan="3">
Appointment</td>
</tr>
<tr>
<td>
Order No:</td>
<td>
<asp:TextBox ID="OrderNo_TextBox" runat="server"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Button ID="Button2" runat="server" Text="Button" />
</td>
</tr>
<tr>
<td>
Type of staff:</td>
<td colspan="2">
<asp:CheckBoxList ID="CheckBoxList4" runat="server">
<asp:ListItem>Photographer</asp:ListItem>
<asp:ListItem>Designer</asp:ListItem>
<asp:ListItem>Stylist</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td>
Search Availability:</td>
<td>
<asp:TextBox ID="SearchTimeAvalability_TextBox" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="SearchTimeAvalability_TextBox_CalendarExtender"
runat="server" Enabled="True"
TargetControlID="SearchTimeAvalability_TextBox" Format="dd/M/yyyy">
</cc1:CalendarExtender>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Button ID="SearchAvailability_Button" runat="server" Text="Search" />
</td>
</tr>
<tr>
<td>
Staff Avalability List:</td>
<td colspan="2">
<asp:GridView ID="GridView1" runat="server"
DataSourceID="StaffAvailabilitySqlDataSource">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="StaffSelector" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="StaffAvailabilitySqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:MilanDatabaseConnectionString1 %>"
SelectCommand="SearchStaffAvailability" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="SearchTimeAvalability_TextBox" DbType="DateTime"
Name="AvailabilityDate" PropertyName="Text" />
<asp:ControlParameter ControlID="CheckBoxList4" Name="RolesName"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
Appointment Time:</td>
<td colspan="2">
<asp:DropDownList ID="Hour_DropDownList" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList>
:<asp:DropDownList ID="Minute_DropDownList" runat="server">
<asp:ListItem>00</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>45</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="AMPM_DropDownList" runat="server">
<asp:ListItem Selected="True">AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Appointment Type:</td>
<td colspan="2">
<asp:DropDownList ID="AppointmentType_DropDownList" runat="server">
<asp:ListItem>Select One</asp:ListItem>
<asp:ListItem>Indoor</asp:ListItem>
<asp:ListItem>Outdoor</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Venue:</td>
<td colspan="2">
<asp:TextBox ID="Venue_TextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="3">
<center><asp:Button ID="NewCustSubmitForm_Button" runat="server" Text="Submit" /></center>
</td>
</tr>
</table>
</asp:Content>
This is the stored procedure for the insert command
@OrderNo varchar(10),
@StaffNo varchar(10),
@AvailabilityDate datetime,
@AppointmentType varchar(10),
@Venue varchar(50)
AS
/* SET NOCOUNT ON */
INSERT INTO StaffAvailability (StaffNo, OrderNo, AvailabilityDate, AppointmentType, Venue)
VALUES (@StaffNo, @OrderNo, @AvailabilityDate, @AppointmentType, @Venue)
RETURN
And this is the event handler
Protected Sub NewCustSubmitForm_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NewCustSubmitForm_Button.Click
Dim selectStaff As New SqlDataSource
selectStaff.ConnectionString = ConfigurationManager.ConnectionStrings("MilanDatabaseConnectionString1").ToString
Dim NewCustomerConnection As String = "Server=KAZESENSEI-PC\SQLEXPRESS;Database=MilanDatabase;Trusted_Connection=True;"
selectStaff.InsertCommandType = SqlDataSourceCommandType.StoredProcedure
selectStaff.InsertCommand = "AddStaffAvailability"
Dim iCount As Integer = 0
Dim dateAndTime As DateTime = Convert.ToDateTime(SearchTimeAvalability_TextBox.Text)
For Each GVR As GridViewRow In GridView1.Rows
If CType(GVR.FindControl("StaffSelector"), CheckBox).Checked = True Then
Dim staffNo As String = GVR.Cells(1).Text
selectStaff.InsertParameters.Add("StaffNo", staffNo)
selectStaff.InsertParameters.Add("OrderNo", OrderNo_TextBox.Text)
selectStaff.InsertParameters.Add("AvailablityDate", dateAndTime)
selectStaff.InsertParameters.Add("AppointmentType", AppointmentType_DropDownList.SelectedValue)
selectStaff.InsertParameters.Add("Venue", Venue_TextBox.Text)
iCount = iCount + 1
End If
Next
Dim rowAffected As Integer = 0
Try
rowAffected = selectStaff.Insert()
Catch ex As Exception
Label1.Text = "Work More"
Finally
selectStaff = Nothing
End Try
If rowAffected <> iCount Then
Label1.Text = "Almost There"
Else
Label1.Text = "Success"
End If
End Sub
If i execute the stored procedure it works find but when it is inserted from the webpage, it didn't return any error and it still won't insert data into the database. Hope if there are anybody that can point out the problem.
Kind Regard