one piece missing

naleignix

New Member
Hi,<BR>My script is almost done (thanks Xanderno) except for one thing. I can open up the connection and close it but I dont know how to write to it. I have tried:<BR><BR>conServices.Open()<BR>cmdInsert.ExecuteNonQuery()<BR>conServices.Close()<BR><BR>But it keeps throwing up Runtime errors. does anybody know any other ways I can write to the database?<BR>my script is.....<BR><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.OleDb" %><BR><BR><BR><Script Runat="Server"><BR><BR>Sub Button_Click(s as Object, e as EventArgs)<BR><BR> Dim conServices as OleDbConnection<BR> Dim strInsert as String<BR> Dim cmdInsert as OleDbCommand<BR><BR><BR>conServices = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:hostingwebhost4lifememberjasoncdatabasess ervices.mdb")<BR><BR>strInsert = "Insert Into (first_name,last_name) Values ("' & txtFirstname.Text & '","' & txtLastname.Text & '") "<BR><BR>cmdInsert = New OleDbCommand(strInsert, conServices)<BR><BR>conServices.Open()<BR><BR><BR>conServices.Close()<BR><BR>response.redirect("http://www.msn.com")<BR><BR>End Sub<BR><BR></Script><BR><BR><BR><html><BR><head><title>Submit Form</title></head><BR><body><BR><BR><form runat="Server"><BR><BR><b>first Name:</b><BR><BR><BR><asp:TextBox<BR>id="txtFirstname"<BR>runat="Server" /><BR><BR><p><BR><BR><b>Last Name:</b><BR><BR><BR><asp:TextBox<BR>id="txtLastname"<BR>runat="Server" /><BR><BR><BR><asp:Button<BR>Text="Submit"<BR>OnClick="Button_Click"<BR>Runat="Server" /><BR><BR><BR><asp:Label<BR> id="lblMessage"<BR> runat="server" /><BR><BR><BR></form><BR></body><BR></html><BR><BR><BR>Thank You.<BR>JCHere ya go....Copy this code, and run it as is. It should work....I changed the db name, and tested it on my system, and it worked beautifully. If you still have problems, most likely, your DB is read only. Make sure that the permissions are set correctly. This code is good though, so it isn't a code problem.<BR><BR><%@ Import Namespace="System.Data" %> <BR><%@ Import Namespace="System.Data.OleDb" %> <BR><%@ Page Language="VB" Debug="true" %> <BR><BR><Script Runat="Server"> <BR><BR>Sub Button_Click(s as Object, e as EventArgs) <BR><BR> Dim conServices as OleDbConnection <BR> Dim strInsert as String <BR> Dim cmdInsert as OleDbCommand <BR> <BR><BR>conServices = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:hostingwebhost4lifememberjasoncdatabasess ervices.mdb"))<BR><BR>strInsert = "Insert Into Services (first_name,last_name) Values ('" & txtFirstname.Text & "','" & txtLastname.Text & "')" <BR><BR>cmdInsert = New OleDbCommand(strInsert, conServices) <BR><BR>conServices.Open() <BR><BR>cmdInsert.ExecuteNonQuery() <BR><BR>conservices.Close() <BR><BR>Response.Redirect("http://www.msn.com") <BR><BR><BR><BR>End Sub <BR><BR></Script> <BR><BR><BR><html> <BR><head><title>Submit Form</title></head> <BR><body> <BR><BR><form runat="Server"> <BR><BR><b>first Name:</b> <BR><BR><BR><asp:TextBox <BR>id="txtFirstname" <BR>runat="Server" /> <BR><BR><p> <BR><BR><b>Last Name:</b> <BR><BR><BR><asp:TextBox <BR>id="txtLastname" <BR>runat="Server" /> <BR><BR><BR><asp:Button <BR>Text="Submit" <BR>OnClick="Button_Click" <BR>Runat="Server" /> <BR><BR><BR><BR></form> <BR><% Response.Write(Server.MapPath("/")) %><BR></body> <BR></html>I jacked it up when I posted it...And added a little left over from my run.<BR><BR>Here ya go...Corrected.<BR><BR><%@ Import Namespace="System.Data" %> <BR><%@ Import Namespace="System.Data.OleDb" %> <BR><%@ Page Language="VB" Debug="true" %> <BR><BR><Script Runat="Server"> <BR><BR>Sub Button_Click(s as Object, e as EventArgs) <BR><BR> Dim conServices as OleDbConnection <BR> Dim strInsert as String <BR> Dim cmdInsert as OleDbCommand <BR> <BR><BR>conServices = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:hostingwebhost4lifememberjasoncdatabasess ervices.mdb")<BR><BR>strInsert = "Insert Into Services (first_name,last_name) Values ('" & txtFirstname.Text & "','" & txtLastname.Text & "')" <BR><BR>cmdInsert = New OleDbCommand(strInsert, conServices) <BR><BR>conServices.Open() <BR><BR>cmdInsert.ExecuteNonQuery() <BR><BR>conservices.Close() <BR><BR>Response.Redirect("http://www.msn.com") <BR><BR><BR><BR>End Sub <BR><BR></Script> <BR><BR><BR><html> <BR><head><title>Submit Form</title></head> <BR><body> <BR><BR><form runat="Server"> <BR><BR><b>first Name:</b> <BR><BR><BR><asp:TextBox <BR>id="txtFirstname" <BR>runat="Server" /> <BR><BR><p> <BR><BR><b>Last Name:</b> <BR><BR><BR><asp:TextBox <BR>id="txtLastname" <BR>runat="Server" /> <BR><BR><BR><asp:Button <BR>Text="Submit" <BR>OnClick="Button_Click" <BR>Runat="Server" /> <BR><BR><BR><BR></form> <BR></body> <BR></html>
 
Back
Top