Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: A simple question.


Message #1 by "Mel C Solomon" <melsolomon@e...> on Tue, 13 Mar 2001 11:48:15 -0800

Hi to all list!!!

I am new and need some help.....

Basically, I want to INSERT new data to my database. I can put my data in datagrid(by following the example in QuickStart) but can't
do a simple adding of new record using ADO.Net.

All I want to do is to add the value inputted in the 2 textbox into the table info.





=====submit.aspx====



<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.ADO" %>



<html>

<script language="C#" runat=server />



void Submit_Now(Object sender, EventArgs e) {

ADOConnection myConnection= new ADOConnection("Provider=Microsoft.Jet.4.0;DataSource="

+Server.MapPath(".\\db\\db1.mdb"); //I'm Sure this connection Works!



myConnection.Open();



//I THINK THIS IS WHERE I'M WRONG....



string strcon= "INSERT INTO info VALUES('"name.Text"','"age.Text"');

ADODataSetCommand myCommand= new ADODataSetCommand(strcon,myConnection);



myConnection.Close();

}

</script>

<body>

<form action="submit.aspx" method="post" runat=server />

<asp:TextBox id="name" runat=server />

<asp:TextBox id="age" runat=server />

<asp:Button id="button1" type=submit Text="Submit" OnClick="Submit_Now" runat=server/> 

</body>

</html>



=========

WhenI opened the table in Access, it doesn't add the new record.



PLEASE HELP ME!!!!!!!!!



THANKS!



__________________________________

www.edsamail.com

Message #2 by John Pirkey <mailjohnny101@y...> on Mon, 12 Mar 2001 08:15:25 -0800 (PST)
Here's the basic code i use to add new records to my database, from ASPX:



Sub cmdsave_click(sender as object, e as eventargs)

dim sql as string

dim cn as adoconnection

dim cmd as adocommand

dim connstr as string



dim sproduct as new stringbuilder(txtproductname.text)

dim sversion as new stringbuilder(txtversion.text)

dim smanufacturer as new stringbuilder(txtmanufacturer.text)

dim sreseller as new stringbuilder(txtreseller.text)



connstr = "provider=sqloledb;server=<YOUR_DATABASE>db;user

id=<YOUR_USERID>;password=<YOUR_PASSWORD>;database=vbugweb;"



cn = new adoconnection(connstr)



sproduct = sproduct.replace("'", "''")

sversion = sversion.replace("'", "''")

smanufacturer = smanufacturer.replace("'", "''")

sreseller = sreseller.replace("'", "''")



sql = "insert into products (productname, version, manufacturer, reseller, cost, "

sql &= "hardware, datereleased) values "

sql &= "('" & sproduct.tostring() & "', '" & sversion.tostring() & "', "

sql &= "'" & smanufacturer.tostring() & "', '" & sreseller.tostring() & "', " &

txtcost.text & ", "

sql &= Cint(opthardware.checked) & ", '" & calMain.SelectedDate.format("d",

Nothing).tostring() & "')"



cn.open

cmd = new adocommand(sql, cn)

cmd.execute()

cn.close



lblstatus.text = txtproductname.text & " was saved successfully."



txtproductname.text = ""

txtversion.text = ""

txtmanufacturer.text = ""

txtreseller.text = ""

txtcost.text = ""



End Sub



I have a comman button on the aspx page named "cmdsave" which fires the above

routine.  



to see this in action - check out www.stlvbug.org and go to the ASP.Net samples

section.



Hope this helps,



john



--- Mel C Solomon <melsolomon@e...> wrote:

> 

> Hi to all list!!!

> I am new and need some help.....

> Basically, I want to INSERT new data to my database. I can put my data in

> datagrid(by following the example in QuickStart) but can't do a simple adding of

> new record using ADO.Net.

> All I want to do is to add the value inputted in the 2 textbox into the table

> info.

> 

> 

> =====submit.aspx====

> 

> <%@ Import Namespace="System.Data" %>

> <%@ Import Namespace="System.Data.ADO" %>

> 

> <html>

> <script language="C#" runat=server />

> 

> void Submit_Now(Object sender, EventArgs e) {

> ADOConnection myConnection= new

> ADOConnection("Provider=Microsoft.Jet.4.0;DataSource="

> +Server.MapPath(".\\db\\db1.mdb"); //I'm Sure this connection Works!

> 

> myConnection.Open();

> 

> //I THINK THIS IS WHERE I'M WRONG....

> 

> string strcon= "INSERT INTO info VALUES('"name.Text"','"age.Text"');

> ADODataSetCommand myCommand= new ADODataSetCommand(strcon,myConnection);

> 

> myConnection.Close();

> }

> </script>

> <body>

> <form action="submit.aspx" method="post" runat=server />

> <asp:TextBox id="name" runat=server />

> <asp:TextBox id="age" runat=server />

> <asp:Button id="button1" type=submit Text="Submit" OnClick="Submit_Now"

> runat=server/> 

> </body>

> </html>

> 

> =========

> WhenI opened the table in Access, it doesn't add the new record.

> 

> PLEASE HELP ME!!!!!!!!!

> 

> THANKS!

> 

> __________________________________

> www.edsamail.com

> 

> 

> 





=====



---------------------------- 

John Pirkey 

MCSD 

John@S... 

http://www.stlvbug.org




  Return to Index