Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems Adding Records

Status
Not open for further replies.

tmishue

Programmer
Jun 26, 2001
35
0
0
US
Hey,

I am trying to add a record to my SQL database. I am using MS InterDev to create my ASP pages. I have a form in which the user inputs the info, then they click to submit the information. When clicking submit they are directed to my Conf.asp which contains the code to add the new record. I am really new to all of this and am totally confused. I tried using the SQL INSERT method but it doesn't work. I also tried the AddRecord Method with the UpdateRecord Method still no luck. I am desperate for some help. I am posting my code to this page. I know it is long but maybe someone can help me figure out what I am doing wrong.


Code:
<%@ Language=VBScript %>
<SCRIPT id=DebugDirectives runat=server language=javascript>
// Set these to true to enable debugging or tracing
@set @debug=true
@set @trace=true
</SCRIPT>

<% ' VI 6.0 Scripting Object Model Enabled %>
<!--#include file=&quot;_ScriptLibrary/pm.asp&quot;-->
<% if StartPageProcessing() Then Response.End() %>
<FORM name=thisForm METHOD=post>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>

Sub cretbtn_onclick()
thisForm.action = &quot;AppointForm.asp&quot;
thisForm.submit
End Sub


</SCRIPT>
</HEAD>
<BODY>
<%
internala = Request.Form(&quot;internaltxt&quot;)
froma = Request.Form(&quot;fromtxt&quot;)
cateogrya = Request.Form(&quot;categorytxt&quot;)
locationa = Request.Form(&quot;locationtxt&quot;)
rooma = Request.Form(&quot;roomtxt&quot;)
subjecta = Request.Form(&quot;subjecttxt&quot;)
personala = Request.Form(&quot;personaltxt&quot;)
toemaila = Request.Form(&quot;toemailtxt&quot;)
startdatea = Request.Form(&quot;startdttxt&quot;)
starttimea = Request.Form(&quot;starttimetxt&quot;)
enddatea = Request.Form(&quot;enddttxt&quot;)
endtimea = Request.Form(&quot;endtimetxt&quot;)

This is the SQL statement that I tried - no luck
Code:
sqlStatemtent = &quot;INSERT INTO calendarinfotable
(DepartmentSchool, Category, Subject, Room, Location, StartDate, StartTime, EndDate, EndTime, Intranet, Toemailm, Personal) VALUES ('&quot;& cstr(froma) & &quot;',' &quot;& cstr(categorya) &&quot;', '&quot;& cstr(subjecta) &&quot;', '&quot;& cstr(rooma) &&quot;', '&quot;& cstr(locationa) &&quot;', '&quot;& cstr(startdatea) &&quot;', '&quot;& cstr(starttimea) &&quot;', '&quot;& cstr(enddatea) &&quot;', '&quot;& cstr(endtimea) &&quot;', '&quot;& cstr(internala) &&quot;', '&quot;& cstr(toemaila) &&quot;', '&quot;& cstr(personala) &&quot;')&quot;

This is the other method I tried - still no luck
Code:
CalRecordset.addRecord
CalRecordset.fields.setValue (&quot;DepartmentSchool&quot;, froma)
CalRecordset.fields.setValue (&quot;Category&quot;, categorya)
CalRecordset.fields.setValue (&quot;Subject', subjecta)
CalRecordset.fields.setValue (&quot;Room&quot;, rooma)
CalRecordset.fields.setValue (&quot;Location&quot;, locationa)
CalRecordset.fields.setValue (&quot;StartDate&quot;, startdatea)
CalRecordset.fields.setValue (&quot;StartTime&quot;, starttimea)
CalRecordset.fields.setValue (&quot;EndDate&quot;, enddatea)
CalRecordset.fields.setValue (&quot;EndTime&quot;, endtimea)
CalRecordset.fields.setValue (&quot;Intranet&quot;, internala)
CalRecordset.fields.setValue (&quot;Toemail&quot;, toemaila)
CalRecordset.fields.setValue (&quot;Personal&quot;, personala)
CalRecordset.updateRecord
 %>

This is the Run Time Text for my DTC Recordset
Code:
<!--#INCLUDE FILE=&quot;_ScriptLibrary/Recordset.ASP&quot;-->
<SCRIPT LANGUAGE=&quot;JavaScript&quot; RUNAT=&quot;server&quot;>
function _initCalRecordset()
{
	if (typeof(Session('s_CalRecordset')) == 'undefined')
	{
		var DBConn = Server.CreateObject('ADODB.Connection');
		DBConn.ConnectionTimeout = Application('CCSCalendar_ConnectionTimeout');
		DBConn.CommandTimeout = Application('CCSCalendar_CommandTimeout');
		DBConn.CursorLocation = Application('CCSCalendar_CursorLocation');
		DBConn.Open(Application('CCSCalendar_ConnectionString'), Application('CCSCalendar_RuntimeUserName'), Application('CCSCalendar_RuntimePassword'));
		var cmdTmp = Server.CreateObject('ADODB.Command');
		var rsTmp = Server.CreateObject('ADODB.Recordset');
		cmdTmp.ActiveConnection = DBConn;
		rsTmp.Source = cmdTmp;
		cmdTmp.CommandType = 2;
		cmdTmp.CommandTimeout = 30;
		cmdTmp.CommandText = '&quot;calendarinfotable&quot;';
		rsTmp.CacheSize = 100;
		rsTmp.CursorType = 3;
		rsTmp.CursorLocation = 3;
		rsTmp.LockType = 3;
		Session('s_CalRecordset') = rsTmp;
	}
	else
		rsTmp = Session('s_CalRecordset');
	CalRecordset.setRecordSource(rsTmp);
	CalRecordset.open();
}
function _CalRecordset_ctor()
{
	CreateRecordset('CalRecordset', _initCalRecordset, null);
}
function _CalRecordset_dtor()
{
	CalRecordset._preserveState();
}
</SCRIPT>


If anyone could give me a clue I would greatly appreciate it!!!


Thanks so much!
tbmishue:-(
 
First of all, what do you mean by &quot;doesn't work&quot;? New record doesn't get inserted into the table, or you get an error?
At first sight there's nothing wrong with your insert
statement, except for one thing: you've misspelled the variable's name(in red)--

internala = Request.Form(&quot;internaltxt&quot;)
froma = Request.Form(&quot;fromtxt&quot;)
[red]cateogrya[/red] = Request.Form(&quot;categorytxt&quot;)
locationa = Request.Form(&quot;locationtxt&quot;)
rooma = Request.Form(&quot;roomtxt&quot;)
subjecta = Request.Form(&quot;subjecttxt&quot;)
personala = Request.Form(&quot;personaltxt&quot;)
toemaila = Request.Form(&quot;toemailtxt&quot;)
startdatea = Request.Form(&quot;startdttxt&quot;)
starttimea = Request.Form(&quot;starttimetxt&quot;)
enddatea = Request.Form(&quot;enddttxt&quot;)
endtimea = Request.Form(&quot;endtimetxt&quot;)
-----------------------
sqlStatemtent = &quot;INSERT INTO calendarinfotable
(DepartmentSchool, Category, Subject, Room, Location, StartDate, StartTime, EndDate, EndTime, Intranet, Toemailm, Personal) VALUES ('&quot;& cstr(froma) & &quot;',' &quot;& cstr(categorya) &&quot;', '&quot;& cstr(subjecta) &&quot;', '&quot;& cstr(rooma) &&quot;', '&quot;& cstr(locationa) &&quot;', '&quot;& cstr(startdatea) &&quot;', '&quot;& cstr(starttimea) &&quot;', '&quot;& cstr(enddatea) &&quot;', '&quot;& cstr(endtimea) &&quot;', '&quot;& cstr(internala) &&quot;', '&quot;& cstr(toemaila) &&quot;', '&quot;& cstr(personala) &&quot;')&quot;

As for AddNew or AddRecord methods, here's a piece of code that inserts a new record into the &quot;good old&quot; pubs database:


<%dim oconn,strconn,ors,strsql
set oconn=server.CreateObject(&quot;ADODB.Connection&quot;)
strconn=&quot;driver={SQL Server};server=[red]your_server_name[/red];
uid=sa;pwd=;database=pubs;&quot;
oconn.Open(strconn)
strsql = &quot;Select * from publishers&quot;
Set ors = Server.CreateObject(&quot;ADODB.Recordset&quot;)
ors.ActiveConnection = oconn
ors.CursorLocation = 3'adUseClient
ors.CursorType = 1 ' adOpenKeyset
ors.LockType = 3'adLockOptimistic
ors.Source = strsql
ors.Open
ors.AddNew
ors(&quot;pub_id&quot;)= &quot;9910&quot;
ors(&quot;pub_name&quot;)= &quot;SFF&quot;
ors(&quot;city&quot;)= &quot;Brooklyn&quot;
ors(&quot;state&quot;)= &quot;NY&quot;
ors(&quot;country&quot;)= &quot;USA&quot;
ors.Update
%>


It works OK.
Try it
 
Thanks for the suggestions. Here's what I tried and still no record is added to my database.
Code:
<% 
internala = Request.Form(&quot;internaltxt&quot;)
froma = Request.Form(&quot;fromtxt&quot;)
categorya = Request.Form(&quot;categorytxt&quot;)
locationa = Request.Form(&quot;locationtxt&quot;)
rooma = Request.Form(&quot;roomtxt&quot;)
subjecta = Request.Form(&quot;subjecttxt&quot;)
personala = Request.Form(&quot;personaltxt&quot;)
toemaila = Request.Form(&quot;toemailtxt&quot;)
startdatea = Request.Form(&quot;startdttxt&quot;)
starttimea = Request.Form(&quot;starttimetxt&quot;)
enddatea = Request.Form(&quot;enddttxt&quot;)
endtimea = Request.Form(&quot;endtimetxt&quot;)
'Response.Write(endtimea)
This is the new recordset that I tried my database name equals beta1 and still no added records
Code:
dim oconn,strconn,ors,strsql
set oconn=server.CreateObject(&quot;ADODB.Connection&quot;)
strconn=&quot;driver={SQL Server};server=beta1;uid=sa;pwd=;database=calendarinfotable;&quot;
oconn.Open(strconn)
strsql = &quot;Select * from calendarinfotable&quot;
Set ors = Server.CreateObject(&quot;ADODB.Recordset&quot;)
ors.ActiveConnection = oconn
ors.CursorLocation = 3'adUseClient
ors.CursorType = 1'adOpenKeyset
ors.LockType = 3'adLockOptimistic
ors.Source = strsql
ors.Open
ors.AddNew
ors(&quot;DepartmentSchools&quot;) = froma
ors(&quot;Category&quot;) = categorya
ors(&quot;Subject&quot;) = subjecta
ors(&quot;Room&quot;) = rooma
ors(&quot;Location&quot;) = locationa
ors(&quot;StartDate&quot;) = startdatea
ors(&quot;StartTime&quot;) = starttimea
ors(&quot;EndDate&quot;) = enddatea
ors(&quot;EndTime&quot;) = endtimea
ors(&quot;Intranet&quot;) = internala
ors(&quot;Toemail&quot;) = toemaila
ors(&quot;Personal&quot;) = personala
ors.Update

This is the SQL Statement That I tried - no records added

Code:
'sqlStatemtent = &quot;INSERT INTO calendarinfotable(DepartmentSchool, Category, Subject, Room, Location, StartDate, StartTime, EndDate, EndTime, Intranet, Toemailm, Personal) VALUES ('&quot;& cstr(froma) & &quot;',' &quot;& cstr(categorya) &&quot;', '&quot;& cstr(subjecta) &&quot;', '&quot;& cstr(rooma) &&quot;', '&quot;& cstr(locationa) &&quot;', '&quot;& cstr(startdatea) &&quot;', '&quot;& cstr(starttimea) &&quot;', '&quot;& cstr(enddatea) &&quot;', '&quot;& cstr(endtimea) &&quot;', '&quot;& cstr(internala) &&quot;', '&quot;& cstr(toemaila) &&quot;', '&quot;& cstr(personala) &&quot;')&quot;
%>


Again any more suggestions will be GREATLY APPRECIATED!!!!!

tbmishue
:-(
 
tmishue,

Try writing your SQL statement to the web page first beofre doing the execution to see hwat the string is.


fengshui1998
 
I wrote the SQL Statement to the asp page and my variable are being passed correctly.

Here is what the statement looked like on the asp page.

INSERT INTO calendarinfotable(DepartmentSchool, Category, Subject, Room, Location, StartDate, StartTime, EndDate, EndTime, Intranet, Toemail, Personal) VALUES ('Cape Fear High',' Band', 'Spring Band Concert', 'Auditorium', 'Cape Fear High', '', '7:00:00 PM', '', '8:00:00 PM', 'Yes', 'cfhs@ccs.k12.nc.us', 'Yes')


Yet still the record is not added to the database. More help pleaseeeeeeeeeeeeeeeeeeeeeee.

tbmishue
:-(
 
I figured out what I was doing wrong. I added my SQL text to my DTC Recordset onbeforeopen event and the record was added. Thanks for all your time and effort in helping me. I truly appreciate it!

tmishue
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top