C
Chumley the Walrus
The below subroutine inserts a new record into my sql database with no
problem, but when I add another field to the list, I get an "Input
string was not in a correct format." error message , coming from the
"Catch ex As Exception
Response.Write(ex.Message)" statement, when I know all my
inputs are going in as strings. See the textbox code below the
subroutine code, as I am doing nothing different when trying to bring
another field into the scheme of things
:::
Sub bntInsert_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
Dim dbComm As New SqlCommand()
dbComm.CommandType = CommandType.Text
dbComm.CommandText = "INSERT INTO Category
(CategoryName,Displaygroup)" & _
"VALUES (@CategoryName, @Displaygroup); SELECT @@IDENTITY AS
'Identity'"
dbComm.Connection = dbConn
dbComm.Parameters.Add("@CategoryName",SqlDbType.VarChar,50)
dbComm.Parameters.Add("@Displaygroup",SqlDbType.Int)
dbComm.Parameters("@CategoryName").Value = txtCategoryName.Text
dbComm.Parameters("@Displaygroup").Value = txtDisplaygroup.Text
Dim iID as Integer
Try
dbConn.Open()
iID = dbComm.ExecuteScalar()
Catch ex As Exception
Response.Write(ex.Message)
Response.End
Finally
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
End Try
Response.Write("The ID of the new record is: " &
iID.ToString())
Response.End
End If
End Sub
:::
:::
<asp:Label id="Label1" runat="server">
CategoryName</asp:Label>
</td>
<td>
<asp:TextBox id="txtCategoryName" runat=
"server"
Width="193"></asp:TextBox>
problem, but when I add another field to the list, I get an "Input
string was not in a correct format." error message , coming from the
"Catch ex As Exception
Response.Write(ex.Message)" statement, when I know all my
inputs are going in as strings. See the textbox code below the
subroutine code, as I am doing nothing different when trying to bring
another field into the scheme of things
:::
Sub bntInsert_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
Dim dbComm As New SqlCommand()
dbComm.CommandType = CommandType.Text
dbComm.CommandText = "INSERT INTO Category
(CategoryName,Displaygroup)" & _
"VALUES (@CategoryName, @Displaygroup); SELECT @@IDENTITY AS
'Identity'"
dbComm.Connection = dbConn
dbComm.Parameters.Add("@CategoryName",SqlDbType.VarChar,50)
dbComm.Parameters.Add("@Displaygroup",SqlDbType.Int)
dbComm.Parameters("@CategoryName").Value = txtCategoryName.Text
dbComm.Parameters("@Displaygroup").Value = txtDisplaygroup.Text
Dim iID as Integer
Try
dbConn.Open()
iID = dbComm.ExecuteScalar()
Catch ex As Exception
Response.Write(ex.Message)
Response.End
Finally
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
End Try
Response.Write("The ID of the new record is: " &
iID.ToString())
Response.End
End If
End Sub
:::
:::
<asp:Label id="Label1" runat="server">
CategoryName</asp:Label>
</td>
<td>
<asp:TextBox id="txtCategoryName" runat=
"server"
Width="193"></asp:TextBox>