pigmentarts
asked on
ASP.NET database help.
all new to asp this is what i have so far, need to write data from a form into my new database. can someone help, any code example i can add to this, just something simple like wrting something to the database.
could you please use my code below as it make it easy for some on new like me.
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859 -1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Ole Db" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="VB" runat="server">
Dim nRecCount As Integer
Dim Query As String = "select * from members"
Dim dbconn=New OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0; data source=" & server.mappath("cl.mdb"))
Dim mySelectCommand as OleDbCommand = New OleDbCommand(Query, dbconn)
Dim myOleDbDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(mySelectC ommand)
dbconn.Close()
</script>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
could you please use my code below as it make it easy for some on new like me.
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Ole
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="VB" runat="server">
Dim nRecCount As Integer
Dim Query As String = "select * from members"
Dim dbconn=New OleDbConnection("Provider=
Dim mySelectCommand as OleDbCommand = New OleDbCommand(Query, dbconn)
Dim myOleDbDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(mySelectC
dbconn.Close()
</script>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
I define my connection string in my web.config, like so:
<appSettings>
<add key="SiteDB" value="Provider=Microsoft. Jet.OleDb. 4.0;Data Source=C:\Inetpub\wwwroot\ DOTNETShop pingCart\D atabase\Si te.mdb;">< /add>
</appSettings>
<appSettings>
<add key="SiteDB" value="Provider=Microsoft.
</appSettings>
ASKER
this is what i have, i need to write the data in to my database called cl.mdb the form, AerosSaga the code looks good but this is my first time with asp so i really want my code below to work so i can go though it. also i am getting a erro alsor...
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30188: Declaration expected.
Source Error:
Line 10: Dim mySelectCommand as OleDbCommand = New OleDbCommand(Query, dbconn)
Line 11: Dim myOleDbDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(mySelectC ommand)
Line 12: dbconn.Close()
Line 13: </script>
Line 14: <head>
-------------------
my code below: at the moment is does nothing just bring a error, what i want is it to write the stuff from the form to my database
-----------------------
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859 -1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Ole Db" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="VB" runat="server">
Dim nRecCount As Integer
Dim Query As String = "select * from members"
Dim dbconn=New OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0; data source=" & server.mappath("cl.mdb"))
Dim mySelectCommand as OleDbCommand = New OleDbCommand(Query, dbconn)
Dim myOleDbDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(mySelectC ommand)
dbconn.Close()
</script>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
<input type="text" id="title" value="Title" runat="server"><br>
<input type="text" id="first_name" value="First Name" runat="server"><br>
<input type="text" id="last_name" value="Last Name" runat="server"><br>
<input type="text" id="company_name" value="Company Name" runat="server"><br>
<input type="text" id="number" value="House Number" runat="server"><br>
<input type="text" id="street" value="Street" runat="server"><br>
<input type="text" id="town" value="Town" runat="server"><br>
<input type="text" id="postcode" value="Postcode" runat="server"><br>
<input type="text" id="telephone" value="Telephone" runat="server"><br>
<input type="text" id="fax" value="Fax" runat="server"><br>
<input type="text" id="email" value="Email" runat="server"><br>
<input type="text" id="password" value="Password" runat="server"><br>
<input type="text" id="web_address" value="Web Address" runat="server"><br>
<select id="sector" runat="server"><br>
<option>Automotive</option >
<option>Computers</option>
<option>Construction</opti on>
<option>Consumer Goods</option>
<option>Education</option>
<option>Electronics</optio n>
<option>Entertainment</opt ion>
<option>Financial Institution</option>
<option>Insurance</option>
<option>Government</option >
<option>Military</option>
<option>Public Sector</option>
<option>Hospitality</optio n>
<option>Recreation</option >
<option>Leisure Industry</option>
<option>Manugacturer</opti on>
<option>Media</option>
<option>Medical</option>
<option>Health Services</option>
<option>Pharmaceuticals</o ption>
<option>Professional Services</option>
<option>Publishers</option >
<option>Retail</option>
<option>Telecommunications </option>
<option>Travel</option>
<option>Transportation</op tion>
<option>Other</option>
</select><br>
<input type="submit" OnServerClick="add_new_mem ber" value="Submit" runat="server"><br>
</form>
</body>
</html>
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30188: Declaration expected.
Source Error:
Line 10: Dim mySelectCommand as OleDbCommand = New OleDbCommand(Query, dbconn)
Line 11: Dim myOleDbDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(mySelectC
Line 12: dbconn.Close()
Line 13: </script>
Line 14: <head>
-------------------
my code below: at the moment is does nothing just bring a error, what i want is it to write the stuff from the form to my database
-----------------------
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Ole
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script language="VB" runat="server">
Dim nRecCount As Integer
Dim Query As String = "select * from members"
Dim dbconn=New OleDbConnection("Provider=
Dim mySelectCommand as OleDbCommand = New OleDbCommand(Query, dbconn)
Dim myOleDbDataAdapter as OleDbDataAdapter = new OleDbDataAdapter(mySelectC
dbconn.Close()
</script>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form runat="server">
<input type="text" id="title" value="Title" runat="server"><br>
<input type="text" id="first_name" value="First Name" runat="server"><br>
<input type="text" id="last_name" value="Last Name" runat="server"><br>
<input type="text" id="company_name" value="Company Name" runat="server"><br>
<input type="text" id="number" value="House Number" runat="server"><br>
<input type="text" id="street" value="Street" runat="server"><br>
<input type="text" id="town" value="Town" runat="server"><br>
<input type="text" id="postcode" value="Postcode" runat="server"><br>
<input type="text" id="telephone" value="Telephone" runat="server"><br>
<input type="text" id="fax" value="Fax" runat="server"><br>
<input type="text" id="email" value="Email" runat="server"><br>
<input type="text" id="password" value="Password" runat="server"><br>
<input type="text" id="web_address" value="Web Address" runat="server"><br>
<select id="sector" runat="server"><br>
<option>Automotive</option
<option>Computers</option>
<option>Construction</opti
<option>Consumer Goods</option>
<option>Education</option>
<option>Electronics</optio
<option>Entertainment</opt
<option>Financial Institution</option>
<option>Insurance</option>
<option>Government</option
<option>Military</option>
<option>Public Sector</option>
<option>Hospitality</optio
<option>Recreation</option
<option>Leisure Industry</option>
<option>Manugacturer</opti
<option>Media</option>
<option>Medical</option>
<option>Health Services</option>
<option>Pharmaceuticals</o
<option>Professional Services</option>
<option>Publishers</option
<option>Retail</option>
<option>Telecommunications
<option>Travel</option>
<option>Transportation</op
<option>Other</option>
</select><br>
<input type="submit" OnServerClick="add_new_mem
</form>
</body>
</html>
Ok first thing if you want to perform a forward only type action such as writing to the database you would want to make it a datareader instead of a dataadapter, much more efficient, however you have a select command not an insert or update command so I guess the first question is what do you really want to do select for display in a datagrid, datalist, repeater or do you want to update your db with information from a form? Let me know and we'll go from there.
Aeros
Aeros
ASKER
sorry about this, I was just having a go, don’t really know what I am doing yet, but I am willing to learn by example, maybe if i explain better you can help
I have a database called cl.mdb, in there database is empty fields called title, name etc.
I need a form that the user can enter there details in like the one bellow
then once submited all this information gets put into my database. I have been told that I need to do it in asp.net vb no c# so they can change later if they like.
any example, and thank you in advanced
<form runat="server">
<input type="text" id="title" value="Title" runat="server"><br>
<input type="text" id="first_name" value="First Name" runat="server"><br>
<input type="text" id="last_name" value="Last Name" runat="server"><br>
<input type="text" id="company_name" value="Company Name" runat="server"><br>
<input type="text" id="number" value="House Number" runat="server"><br>
<input type="text" id="street" value="Street" runat="server"><br>
<input type="text" id="town" value="Town" runat="server"><br>
<input type="text" id="postcode" value="Postcode" runat="server"><br>
<input type="text" id="telephone" value="Telephone" runat="server"><br>
<input type="text" id="fax" value="Fax" runat="server"><br>
<input type="text" id="email" value="Email" runat="server"><br>
<input type="text" id="password" value="Password" runat="server"><br>
<input type="text" id="web_address" value="Web Address" runat="server"><br>
<select id="sector" runat="server"><br>
<option>Automotive</option >
<option>Computers</option>
<option>Construction</opti on>
<option>Consumer Goods</option>
<option>Education</option>
<option>Electronics</optio n>
<option>Entertainment</opt ion>
<option>Financial Institution</option>
<option>Insurance</option>
<option>Government</option >
<option>Military</option>
<option>Public Sector</option>
<option>Hospitality</optio n>
<option>Recreation</option >
<option>Leisure Industry</option>
<option>Manugacturer</opti on>
<option>Media</option>
<option>Medical</option>
<option>Health Services</option>
<option>Pharmaceuticals</o ption>
<option>Professional Services</option>
<option>Publishers</option >
<option>Retail</option>
<option>Telecommunications </option>
<option>Travel</option>
<option>Transportation</op tion>
<option>Other</option>
</select><br>
<input type="submit" OnServerClick="add_new_mem ber" value="Submit" runat="server"><br>
</form>
I have a database called cl.mdb, in there database is empty fields called title, name etc.
I need a form that the user can enter there details in like the one bellow
then once submited all this information gets put into my database. I have been told that I need to do it in asp.net vb no c# so they can change later if they like.
any example, and thank you in advanced
<form runat="server">
<input type="text" id="title" value="Title" runat="server"><br>
<input type="text" id="first_name" value="First Name" runat="server"><br>
<input type="text" id="last_name" value="Last Name" runat="server"><br>
<input type="text" id="company_name" value="Company Name" runat="server"><br>
<input type="text" id="number" value="House Number" runat="server"><br>
<input type="text" id="street" value="Street" runat="server"><br>
<input type="text" id="town" value="Town" runat="server"><br>
<input type="text" id="postcode" value="Postcode" runat="server"><br>
<input type="text" id="telephone" value="Telephone" runat="server"><br>
<input type="text" id="fax" value="Fax" runat="server"><br>
<input type="text" id="email" value="Email" runat="server"><br>
<input type="text" id="password" value="Password" runat="server"><br>
<input type="text" id="web_address" value="Web Address" runat="server"><br>
<select id="sector" runat="server"><br>
<option>Automotive</option
<option>Computers</option>
<option>Construction</opti
<option>Consumer Goods</option>
<option>Education</option>
<option>Electronics</optio
<option>Entertainment</opt
<option>Financial Institution</option>
<option>Insurance</option>
<option>Government</option
<option>Military</option>
<option>Public Sector</option>
<option>Hospitality</optio
<option>Recreation</option
<option>Leisure Industry</option>
<option>Manugacturer</opti
<option>Media</option>
<option>Medical</option>
<option>Health Services</option>
<option>Pharmaceuticals</o
<option>Professional Services</option>
<option>Publishers</option
<option>Retail</option>
<option>Telecommunications
<option>Travel</option>
<option>Transportation</op
<option>Other</option>
</select><br>
<input type="submit" OnServerClick="add_new_mem
</form>
ASKER
ps i may also want a page after to confirm details on screen if you knwo what i mean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you very much. been a good help, may need help later will post again. take care
your very welcome glad I could be of service
Aeros
Aeros
<TABLE cellSpacing="0" cellPadding="5" width="550" border="0">
<TR>
<TD class="PageHeader" style="HEIGHT: 24px" colSpan="2">Add New Product</TD>
</TR>
<TR>
<TD width="192">Product N
<TD width="338"><asp:textbox id="ProductName" runat="server" CssClass="ThinInput" Columns="15" MaxLength="50"></asp:textb
<asp:requiredfieldvalidato
ControlToValidate="Product
</TR>
<TR>
<TD style="HEIGHT: 15px" width="192">Tier1</TD>
<TD style="HEIGHT: 15px" width="338"><asp:dropdownl
<asp:requiredfieldvalidato
ErrorMessage="Please select a tier1."></asp:requiredfiel
</TR>
<TR>
<TD width="192">Tier2 <SPAN class="SmallText">(optiona
<TD width="338"><asp:dropdownl
</TR>
<TR>
<TD width="192">Tier3 <SPAN class="SmallText">(optiona
<TD width="338"><asp:dropdownl
</TR>
<TR>
<TD vAlign="top">Description <SPAN class="SmallText">(optiona
<TD><asp:textbox id="Description" runat="server" CssClass="ThinInput" Columns="35" MaxLength="255"
TextMode="MultiLine" Rows="3"></asp:textbox></T
</TR>
<TR>
<TD style="HEIGHT: 34px">Picture <SPAN class="SmallText">(optiona
<TD style="HEIGHT: 34px"><INPUT class="ThinInput" id="ImageSrc" type="file" size="15" runat="server"></TD>
</TR>
<TR>
<TD style="HEIGHT: 34px">Price <SPAN class="SmallText">(optiona
<TD style="HEIGHT: 34px"><asp:textbox id="Price" runat="server" CssClass="ThinInput" Columns="4" MaxLength="7"></asp:textbo
</TR>
<TR>
<TD align="right" colSpan="2"><asp:button id="AddProduct" runat="server" CssClass="ThinButton" Width="98px" CausesValidation="False"
Text="Add Product"></asp:button></TD
</TR>
<TR>
<TD colSpan="2"><asp:label id="StatusLabel" runat="server"></asp:label
</TR>
</TABLE>
Region " AddProduct Button "
Private Sub AddProduct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddProduct.Click
If IsRefresh Then Return
ProductNameValidator.Enabl
Tier1Validator.Enabled = True
QueryValidator.Enabled = False
Validate()
If Not IsValid Then Return
Dim cnn As New OleDb.OleDbConnection(Conf
Dim cmd As New OleDb.OleDbCommand
Dim IncomingFile As IO.FileInfo
Dim ImageSource, PriceValue As String
Dim ImageResizer As New ResizeImage(True, 300, 400)
ImageResizer.ThumbX = 100
ImageResizer.ThumbY = 100
If ImageSrc.PostedFile.Conten
IncomingFile = New IO.FileInfo(Request.Files(
IncomingFile = New IO.FileInfo(Server.MapPath
Request.Files(0).SaveAs(In
ImageSource = ImageResizer.ResizeImage(I
End If
If Price.Text = "" Then
PriceValue = "0"
Else
PriceValue = Price.Text
End If
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO Products (Tier1ID, Tier2ID, Tier3ID, Name, " & _
"Description, ImageSrc, Price) VALUES (" & Tier1.SelectedValue & ", " & _
Tier2.SelectedValue & ", " & Tier3.SelectedValue & ", '" & DBSafe(ProductName.Text) & _
"', '" & DBSafe(Description.Text) & "', '" & ImageSource & "', " & PriceValue & ")"
cmd.Connection = cnn
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
cmd.Dispose()
cnn.Dispose()
LoadProductData()
End Sub
#End Region
Let me know if you need any more help
Regards,
Aeros