HI,
I'm creating an update form for update a records within a db.
The update routine is working if I hard code value into it.
The problem is that the form values are not being passed into the parameters.
Here is the code:
[HTML]Sub UpdateRec(Sourc e as Object, E as EventArgs)
dim dsn As String = ConfigurationSe ttings.AppSetti ngs("SystemConn ectionNew")
dim objConn as New SqlConnection(d sn)
Dim UpdateCommand As SqlCommand = New SqlCommand()
UpdateCommand.C onnection = objConn
Dim sql As String
sql = "UPDATE tbl_ACCO_EU_Con tacts SET Title=@Title WHERE EndUserID=@EndU serID"
UpdateCommand.C ommandText = sql
UpdateCommand.P arameters.Add(N ew SqlParameter("@ Title", textTitle.Text) )
'UpdateCommand. Parameters("@Ti tle").Value = textTitle.Text
UpdateCommand.P arameters.Add(" @EndUserID", SqlDbType.Int). Value = 13
Try
objConn.Open()
UpdateCommand.E xecuteNonQuery( )
Catch ex As Exception
response.Write( ex.ToString())
Finally
objConn.Close()
End Try
'response.Redir ect("record_src h.aspx")
End sub[/HTML]
Here is the form:
[HTML]<form runat="server" name="selform">
<ol>
<li >
<label for="textTitle" >Title:</label>
<asp:TextBox ID="textTitle" runat="server" />
</li>
<asp:TextBox Visible="false" ID="textEndUser ID" runat="server" />
<li>
<asp:Button ID="btnUpdate" Text="Update Record" Enabled="false" OnClick="Update Rec" runat="server" /></li>
</ul>
</ol>
</form>[/HTML]
Any help would be great.
Adz
I'm creating an update form for update a records within a db.
The update routine is working if I hard code value into it.
The problem is that the form values are not being passed into the parameters.
Here is the code:
[HTML]Sub UpdateRec(Sourc e as Object, E as EventArgs)
dim dsn As String = ConfigurationSe ttings.AppSetti ngs("SystemConn ectionNew")
dim objConn as New SqlConnection(d sn)
Dim UpdateCommand As SqlCommand = New SqlCommand()
UpdateCommand.C onnection = objConn
Dim sql As String
sql = "UPDATE tbl_ACCO_EU_Con tacts SET Title=@Title WHERE EndUserID=@EndU serID"
UpdateCommand.C ommandText = sql
UpdateCommand.P arameters.Add(N ew SqlParameter("@ Title", textTitle.Text) )
'UpdateCommand. Parameters("@Ti tle").Value = textTitle.Text
UpdateCommand.P arameters.Add(" @EndUserID", SqlDbType.Int). Value = 13
Try
objConn.Open()
UpdateCommand.E xecuteNonQuery( )
Catch ex As Exception
response.Write( ex.ToString())
Finally
objConn.Close()
End Try
'response.Redir ect("record_src h.aspx")
End sub[/HTML]
Here is the form:
[HTML]<form runat="server" name="selform">
<ol>
<li >
<label for="textTitle" >Title:</label>
<asp:TextBox ID="textTitle" runat="server" />
</li>
<asp:TextBox Visible="false" ID="textEndUser ID" runat="server" />
<li>
<asp:Button ID="btnUpdate" Text="Update Record" Enabled="false" OnClick="Update Rec" runat="server" /></li>
</ul>
</ol>
</form>[/HTML]
Any help would be great.
Adz