HOME ➔ SUPPORT ➔ Community ➔ General CourseLab issues ... Inserting data into database using ASP.NET
Inserting data into database using ASP.NET
  View type:
Hi,
i m trying to insert data from the textbox into database using EXTERNAL URL(which call ASP.NET) but the value in the textbox could not be detected. Any suggestion or solution?
Thanks in advance.
 
Hi Nee,
There will be a few ways to do this. From a strict standards development viewpoint you're going to need to use the ado.net functions part of .net) which handle data access to create the connection to the database in the first place, just trying to push data somewhere but without the explicit link to a database won't do anything.

As Courselab isn't using .net implicitly then this might be a bit painful to achieve. It also will require a server to handle the read/writes, again unless running on an M$ server (the module is handled by a remote server and isn't running as an app on the local PC).
It might be possible on a standalone PC to startup a small instance of apache or tomcat but it could hit some big security problems in setting it up on W2K, XP and especially Vista. It will also require some customisation of the Courselab generated files and the API itself which will need solid knowledge of Javascript.
Another alternative might be AJAX but again you're going to have to develop some javascript modules to handle the events and code within Courselab itself to do something with it at page level.

The basic steps you need to cover will be:
#1. Create a database connection so you can connect to the database.
#2. Create a dbcomm variable as a new OleDbCommand class so you can issue sql commands to the database.
#3. Create a data reader or writer as required.
#4. Bind the reader or writer to a control.
#5. Close the database connection.

You might better off trying this in visual studio which essentially means rewriting the entire module in asp, almost a total reinvention of the wheel would describe what you need to do. Unless you are happy using VB and the net environment this is going to be a big job with a very steep learning curve.

Another option might be to use Flash which can handle connections to databases, you still need to do the equivalent steps but it might be easier as the final flash object could be inserted into a module page on Courselab. For this you're going to need medium to advanced knowledge of flash action script.

The general thing you've probably noticed is that it isn't going to be as simple as you would like it to be. Just trying to push a variable without a lot of supporting structure won't work.
 
 
A simple ado database connector script looks like this when using a jet engine (MS_Access database)

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

<script runat="server">
sub Page_Load
dim dbconn
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("my_database_name.mdb"))
dbconn.Open()
end sub
</script>

Adding in a database command ends up looking like this, in this case this will read the records from the record record_name in the my_database_name database.

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

<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("my_database_name.mdb"))
dbconn.Open()
sql="SELECT * FROM record_name"
dbcomm=New OleDbCommand(sql,dbconn)
end sub
</script>

Oh I forgot to mention that you'll also need to know how to make SQL queries!!
 
 
 
Sorry [:(] the scripts get hidden by the forums html

The first script section is:
runat="server"
sub Page_Load
dim dbconn
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("my_database_name.mdb"))
dbconn.Open()
end sub

and then to read a record set

runat="server"
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("my_database_name.mdb"))
dbconn.Open()
sql="SELECT * FROM record_name"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
end sub

Writing adds a few more complexities but all of this is well covered in numerous tutorials available on the web.
The code itself will be a little different for SQL or HSQL and other db engines but overall very similar where the server itself runs the query or write to a record set.
Subject:
Message options
No additional options