|
 |
aspx_beginners thread: sending values from a form to stored procedures
Message #1 by jmnamahoe@h... on Wed, 29 May 2002 00:36:14
|
|
does anyone have experience with passing values from a form to a stored
procedure in an MS Access DB. how do you pass the values from the form to
a stored procedure, and could you provide an example. any help/examples
would be appreciated. thanx.
maui
Message #2 by "Sri Vidya" <svsvidya@i...> on Wed, 29 May 2002 10:34:10 +0530
|
|
Hi,
I have pasted two separate code examples, the first one READS data
from the PUBS DATABASE (Here I am using SQL SERVER, just change the
connection parameters to point to ACCESS DATABASE).
The second example WRITES data into database table.
HTH.
Cheers,
Vidya.
=======================================================================
EXAMPLE - 1 : READ VALUES FROM THE DATABASE TABLE. (PARAMETERISED
QUERY)
=======================================================================
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Button_Click(s as object, e as eventargs)
dim conPubs as SqlConnection
dim cmdSelect as Sqlcommand
dim strSelect as string
dim dtrResults as SqlDataReader
'prepare the select statement
strSelect = "Select Phone from Authors where au_fname=@firstname And
au_lname=@lastname"
'set connection string.
conPubs = New SqlConnection(
"server=blrgtpinfo2;uid=sa;pwd=;database=pubs")
cmdSelect = New SqlCommand(strselect, conpubs)
cmdSelect.parameters.Add("@firstname", txtFN.Text)
cmdSelect.parameters.Add("@lastname", txtLN.Text)
' open connection
conpubs.open()
lblPhone.Text = cmdSelect.ExecuteScalar()
' close connection
conPubs.Close()
end sub
</script>
<html>
<head>
<title> sqlParam.aspx </title>
</head>
<body>
<form runat="server">
<h2> Author Phone Lookup </h2>
<b> First Name: </b>
<br>
<asp:TextBox id="txtFN" Runat="server" />
<p>
<b> Last Name: </b>
<br>
<asp:TextBox id="txtLN" Runat="Server" />
<p>
<asp:Button Text="Look Up" OnClick="Button_Click" Runat="server" />
<p>
<b> Phone: </b>
<asp:Label id="lblPhone" EnableViewState="False" Runat="server" />
</form>
</body>
</html>
=======================================================================
EXAMPLE - 2
=======================================================================
<%@ Import Namespace = "System.data.sqlclient" %>
<%
Dim connw as sqlconnection
dim strinsert as string
dim cmdinsert as sqlcommand
'open the connection
connw = new
sqlconnection("server=sqlserver;uid=sa;pwd=;database=northwind")
'prepare the insert statement
strinsert = "Insert Products(ProductName, UnitPrice) VALUES('Milk',
12.45)"
'Execute the insert statement.
cmdinsert = new sqlcommand(strinsert, connw)
connw.open()
cmdinsert.executenonquery()
connw.close()
%>
New Product Inserted into the database!
=======================================================================
On Wed, 29 May 2002 00:36:14
jmnamahoe@h... wrote:
>does anyone have experience with passing values from a form to a
>stored
>procedure in an MS Access DB. how do you pass the values from the
>form to
>a stored procedure, and could you provide an example. any
>help/examples
>would be appreciated. thanx.
>
>maui
---------------------------------------------
http://mail.indiainfo.com
India's first ISO certified portal
Check world time at http://time.indiainfo.com
|
|
 |