...

View Full Version : how to save file to ms access database using javascript?



Jianet
05-03-2005, 09:47 AM
hi guys!
This is my question...
how to save file to ms access database using javascript?
Is it possible?

please posts any reply.....
thanks...

jbot
05-03-2005, 10:47 AM
check out ActiveX Data Objects (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/dasdkadooverview.asp), then look up how to create an ActiveX object (http://msdn.microsoft.com/library/en-us/script56/html/js56jsobjActiveXObject.asp?frame=true) in IE using JScript (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp). However, it should be noted that this is only achievable in Win IE, and no other browser at all, furthermore it is only suitable for clientside applications.

Jianet
05-04-2005, 03:02 AM
this is my codes..
please do any correction!
I dont know how to do this...

<script language="VBScript">

Dim objRS, aConnectionString, DBObj

aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Documents and Settings\Administrator.VFI\My Documents\MyRequest.mdb"
Set DBObj=Server.CreateObject("ADODB.Connection")
DBObj.ConnectionString = aConnectionString
DBObj.Open
SQLQuery = "INSERT * FROM MyRequest1"
Set objRS=DBObj.Execute(SQLQuery)

objRS.AddNew
objRS.Fields("Requestor") = Request.Form("Requestor")
objRS.Fields("Department") = Request.Form("Department")
objRS.Fields("Date") = Request.Form("Date")
objRS.Fields("Deadline") = Request.Form("Deadline")
objRS.Fields("Status") = Request.Form("Status")
objRS.Fields("Particulars") = Request.Form("Particulars")
objRS.Fields("Comments") = Request.Form("Comments")
objRS.Update
objRS.Close
Set objRS = nothing
objConn.Close
Set objConn = nothing
</SCRIPT>

jbot
05-04-2005, 10:21 AM
so what error do you get. please note, i can't test your code because I don't have Access or your DB.

Jianet
05-04-2005, 10:47 AM
No error displayed but still no effect..
I have forms named(requestor,department,date,deadline,status,particulars,comments). then once i filled up the form and click the save button..all the files should be sent to my access database but unfortunately it can't save file and file does'nt stored to my database.
Can you help me? Is there any lacking?

jbot
05-04-2005, 10:50 AM
No error displayed but still no effect

we need to see more of your code, particularly the HTML. (use Code tags to format it nicely for us!)

Jianet
05-04-2005, 11:14 AM
Here is my codes...
excluding the connection bec. it is already posted...
Please help on how to do this completely.

<html>
<head>
</head>
<body>
<table border="0" width="901">
<tr>
<form name=" ">
<td width="300"><font size="4">
<pre>Requestor:<input type="text" name="Requestor" value=""
style="border:0px"></pre></font></td>
</form>
<p align="right">
<script type="text/javascript">
var d = new Date()
document.write("Date: ")
document.write(d.getDate())
document.write("/")
document.write(d.getMonth() + 1)
document.write("/")
document.write(d.getFullYear())
</script>
</p>
<tr>
<form name=" ">
<td width="300"><font size="4"><pre>Department:<input type="text" name="Department" style="border:0px" ></pre></font></td>
<td width="1000">
<p align="right"><font size="4">Deadline:<input type="text" name="Deadline" style="border:0px" size="15"> </font></td>
</tr>
<tr>
<td width="300">
<p align="right">
<td width="579">
<p align="right"
<select name="Status">Status <select>
<option value="UnServed">UnServed</option>
<font size="4">Status <size="20"> </select> </p></td>
<td width="2">
</tr>
</table>
<p></p>
<center>
<table border="0">
<tr>
<th>Particulars/Request</th>
<th>Reaction/Comments</th>
</tr>
<td><textarea rows="10" cols="37"></textarea> </td>
<td><textarea rows="10" cols="37"></textarea></td>
</table>
</center>
<form>
<p align="center">
<a href="MyRequest.mdb" target="_blank">Open</a>
<td></td><td><a title="Save" class="button" href="javascript:document.forms[0].submit()">Save</a >
<a title="Cancel" class="button" href="javascript:document.forms[0].submit()">Cancel</a><input type="hidden" name="action" value="none"/>
</form>
<table>
</table>
</body>
</html>

jbot
05-04-2005, 11:18 AM
your form won't submit because it's got no action to submit to. however, because your attempting to use JS to write to a Access DB (why you don't submit to an ASP page is beyond me), you need to call a function which then uses ADO to write to the Access DB. that's why nothing happens, because your not telling the program to do anything.

Jianet
05-04-2005, 11:22 AM
Can you add the codings of my program?
How to put a function so that the button will work?

jbot
05-04-2005, 11:31 AM
I don't have time to do that. your VBS code really needs a complete overhaul, as does the HTML. I'd like to help, but I've got my own work to do which kind of suffers when I'm on here.

here are some hints tho:


because you're using VBS, you need to change the language of your buttons to VBS also in order that they call the VBS function that your going to write next
create a function for writing to the DB. you can find out how to do that on MSDN

Jianet
05-04-2005, 11:40 AM
Thank you for sharing your knowledge...

I just wanna ask some questions about this if its ok for you and your free...
but this time, can you give me a little bit codes.......please!!!!!

jbot
05-04-2005, 11:47 AM
something like this:



Function UpdateDb()
objRS.AddNew
objRS.Fields("Department") = document.forms[0].Department
objRS.Update
End Function



<a language="vbscript" title="Save" class="button" href="#" onclick="return UpdateDb()">Save</a>

Jianet
05-04-2005, 11:58 AM
Thanks!
Can I approach you anytime i encountered some complicated codes of my program?
I need more help from somebody because i am a student right now.. and i want to learn more about JS....
God Bless!!!

jbot
05-04-2005, 12:25 PM
Can I approach you anytime i encountered some complicated codes of my program?

just post as normal and someone's bound to help.



I need more help from somebody because i am a student right now.. and i want to learn more about JS.

what you've got isn't JS, but is Visual Basic Script (VBS/VBScript). you can only use it in Internet Explorer, so it's not really suitable for the web. JS, on the other hand, can be delightful to use so don't be put off if it ever appears obtuse. by the same token, don't imagine it can do everything because it can't.



God Bless!!!

and you :thumbsup:

Jianet
05-05-2005, 02:30 AM
Hi jbot...
what is the use of href="#"
I try to apply the codes but still no changes...Can you give me codes?
please help me to solve the problem. I am using vbscript now...

Jianet
05-05-2005, 02:35 AM
Is there anybody could help me to solve the problem of my program?
Please posts any reply!
Thanks...

Basscyst
05-05-2005, 03:48 AM
This got me going good:

http://www.codingforums.com/showthread.php?t=31730

Here is a program I wrote using ActiveX as you are trying to do. Feel free to look at it for some code examples.

http://www.codingforums.com/showthread.php?t=46506&highlight=Basscyst

Hope that helps,
Basscyst

Jianet
05-05-2005, 04:04 AM
Can you help me make the codes of my program?The codes are already posted...please make any correction...I need your help!


Basscyst

Basscyst
05-05-2005, 04:18 AM
Most people will not give away their fish, you can either buy them or learn to fish yourself. They teach fishing here (http://www.w3schools.com/). More specifically for your needs here (http://www.w3schools.com/sql/default.asp) and here (http://www.w3schools.com/ado/default.asp). If you just want to pay for some fish try here (http://www.codingforums.com/forumdisplay.php?f=36).

Good luck,
Basscyst

Jianet
05-05-2005, 04:51 AM
basscyst

The codes you've made wont save file to ms access database...It is only on the table...what if I used vbscript,can you tell me, what are those important codes needed in sending file to my ms access database? I am finish exploring about it,I'll do the best of my ability but still no output....what should i do?

glenngv
05-05-2005, 07:19 AM
this is my codes..
please do any correction!
I dont know how to do this...

<script language="VBScript">

Dim objRS, aConnectionString, DBObj

aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Documents and Settings\Administrator.VFI\My Documents\MyRequest.mdb"
Set DBObj=Server.CreateObject("ADODB.Connection")
DBObj.ConnectionString = aConnectionString
DBObj.Open
SQLQuery = "INSERT * FROM MyRequest1"
Set objRS=DBObj.Execute(SQLQuery)

objRS.AddNew
objRS.Fields("Requestor") = Request.Form("Requestor")
objRS.Fields("Department") = Request.Form("Department")
objRS.Fields("Date") = Request.Form("Date")
objRS.Fields("Deadline") = Request.Form("Deadline")
objRS.Fields("Status") = Request.Form("Status")
objRS.Fields("Particulars") = Request.Form("Particulars")
objRS.Fields("Comments") = Request.Form("Comments")
objRS.Update
objRS.Close
Set objRS = nothing
objConn.Close
Set objConn = nothing
</SCRIPT>
As I see your code, this is not Javascript (so your thread title is misleading) and not even client-side VBScript as you intend to do with that <script> tag. It is an ASP page written in server-side VBScript because of that Request.Form statements. So to make it run server-side, you need to add runat="server" in the <script> tag.


<script language="VBScript" runat="server">

or simply enclose the code in <% %>


<%
Dim objRS, aConnectionString, DBObj
...
Set objConn = nothing
%>
Before we'll be able to help you, you need first to make your requirements clear. Do you want it to be Javacript, VBScript client-side or server-side or what? :confused:

Jianet
05-05-2005, 07:29 AM
Glenn
It is vbscript Server side....I'ts quite difficult...
Thats the reason why I need help!
Whats the better programming language for saving data to ms access database?
Hopefully somebody could help me...

glenngv
05-05-2005, 08:21 AM
You should have made that clear from the very start as others were confused that you want to do it client-side. Added to the confusion is you posted this in the wrong forum. Ask the mod to move this to ASP forum to get more response and don't cross-post.

Back to the problem...
Try what I suggested in my previous post. And then post here if you encountered problem when the code is run.

Jianet
05-05-2005, 09:34 AM
I'm Sorry...

glenngv
05-05-2005, 09:43 AM
Ok, forgiven. ;)
Now, have you tried what I suggested?

Jianet
05-05-2005, 09:53 AM
yes i try but nothing happen....
please help me...

glenngv
05-05-2005, 10:38 AM
Try this:

<%
Function CSQ(byVal str)
If IsNull(str) Then str = ""
CSQ = Replace(str,"'","''")
End Function

Dim objRS, aConnectionString, DBObj, SQLQuery

aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Documents and Settings\Administrator.VFI\My Documents\MyRequest.mdb"
Set DBObj=Server.CreateObject("ADODB.Connection")
DBObj.ConnectionString = aConnectionString
DBObj.Open
SQLQuery = "INSERT INTO MyRequest1 ([Requestor], [Department], [Date], [Deadline], [Status], [Particulars], [comments]) VALUES (" & _
"'" & CSQ(Request.Form("Requestor")) & "'," & _
"'" & CSQ(Request.Form("Department")) & "'," & _
"'" & CSQ(Request.Form("Date")) & "'," & _
"'" & CSQ(Request.Form("Deadline")) & "'," & _
"'" & CSQ(Request.Form("Status")) & "'," & _
"'" & CSQ(Request.Form("Particulars")) & "'," & _
"'" & CSQ(Request.Form("Comments")) & "')"

'uncomment this if you want to debug the SQL statement
'response.write SQLQuery
'response.end

Set objRS = DBObj.Execute(SQLQuery)
objRS.Close
Set objRS = nothing
objConn.Close
Set objConn = nothing
%>

jbot
05-05-2005, 10:41 AM
given that the application is now serverside, you need to have your form point to the page the data is being submitted to. you do this via the form's action attribute.

Jianet
05-05-2005, 10:53 AM
Glenn...
what about the buttons....How to put a function?

Jianet
05-05-2005, 10:56 AM
Jpot...

Do you mean I need to have two(2) programs?the one program is my form and the other for my database?

jbot
05-05-2005, 11:06 AM
Do you mean I need to have two(2) programs?the one program is my form and the other for my database?

yes, you need a page which transmits the form data to the server whereupon your ASP application parses it.

Jianet
05-05-2005, 11:11 AM
Jbot..

Just like this..
<form method="post" action="requestform.asp">
can you add this?

jbot
05-05-2005, 11:14 AM
yes, just like that, where the value of action is the page to which the form submits its field data. it should really be a different page which is submitting the data: it can get messy coding it all in one, so best avoid, especially given your noobness. :D

Jianet
05-05-2005, 11:18 AM
Jbot..

Can you give me even sample codes for this?

glenngv
05-05-2005, 11:18 AM
You definitely need to spend time reading these ASP, VBScript and ADO tutorials.

http://www.w3schools.com/asp/
http://www.w3schools.com/vbscript/
http://www.w3schools.com/ado/

jbot
05-05-2005, 11:22 AM
and any HTML tutorials which relate to forms. Google (http://google.com) is your friend. :thumbsup:

Jianet
05-05-2005, 11:29 AM
Jbot..

I have no problem speaking of forms...I mean,the codes that can give a function of the button...if it is in separate page...

glenngv
05-05-2005, 11:44 AM
If you read the ADO tutorial that I linked you to, you will see a demo (http://www.w3schools.com/ado/demo_db_add.asp) that inserts records to the database. If you really want to learn, you need to make an extra effort to do so instead of asking people here to give you sample codes.

Jianet
05-05-2005, 11:48 AM
ok...
You know,I try ADO on how to insert but It wont work...thats the reason why i ask here expecting someone to share their knowledge...because I dont know where part of my program I made mistakes...
Thank you for the time...

jbot
05-05-2005, 11:51 AM
If you read the ADO tutorial that I linked you to, you will see a demo (http://www.w3schools.com/ado/demo_db_add.asp) that inserts records to the database. If you really want to learn, you need to make an extra effort to do so instead of asking people here to give you sample codes.

there was also several important links in the second post in the thread. asking for help is all very well, but you've gotta do it for yourself as well. we all get stuck, but it is important to be able to do the basics in the first place and not jump straight in at the deep end. either way don't panic - there's plenty of information online to help you out. :thumbsup:

Jianet
05-05-2005, 12:00 PM
Thank you for reminding me that, start from the very basics...honestly this is my first time in doing javascripts/vbscripts and i am not familiar with the codes...I studied it well before i ask help...but when i came to the most complicated part,I've got discouraged...until such time,I come up with the coding forums and I am willing to join because I really want to learn..
Thank you guys!!!

faulkj
04-21-2009, 09:04 AM
You are able to connect to Microsoft Access using JavaScript when the HTML file is run locally and the Access .mdb file is accessible to the file system.

I had a situation where this functionality was actually useful, so I wrote a JavaScript library to simplify the process. I had a great deal of difficulty finding information or examples of how to connect to Access, so I decided to share my codewith the world...

The library is called ACCESSdb (http://www.accessdb.org) and you can get it here (http://www.accessdb.org)!

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum