By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,385 Members | 847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,385 IT Pros & Developers. It's quick & easy.

about insert/delete/update records in mysql server with asp code

P: 3
about insert/delete/update records in mysql server with asp code

how can I insert record in mysql database.. I insert into database but if I leave one text box empty, its give me error how can overcome on it...

my code is like
"INSERT INTO hamp6 VALUES ('" & request.QueryString("FRAME_WORK_ARRANGEMENT_REF_NU M")& "', '" & request.QueryString("TASK_ORDER_FORM_REFERENCE_NUM BER") &"', '" & request.QueryString ("TASK_TITLE") &"', '" & request.QueryString ("PROJECT_SPONSOR") &"', '" & request.QueryString("TEL") &"', '" & request.QueryString("PROPOSED_TASK")&"', '" & request.QueryString("DURATION")&"', '" & request.QueryString("BUSINESS_CASE") &"', '" & request.QueryString("TOTAL_ESTIMATE_COST")&"')"
Mar 5 '07 #1
Share this Question
Share on Google+
3 Replies


jhardman
Expert 2.5K+
P: 3,405
about insert/delete/update records in mysql server with asp code

how can I insert record in mysql database.. I insert into database but if I leave one text box empty, its give me error how can overcome on it...

my code is like
"INSERT INTO hamp6 VALUES ('" & request.QueryString("FRAME_WORK_ARRANGEMENT_REF_NU M")& "', '" & request.QueryString("TASK_ORDER_FORM_REFERENCE_NUM BER") &"', '" & request.QueryString ("TASK_TITLE") &"', '" & request.QueryString ("PROJECT_SPONSOR") &"', '" & request.QueryString("TEL") &"', '" & request.QueryString("PROPOSED_TASK")&"', '" & request.QueryString("DURATION")&"', '" & request.QueryString("BUSINESS_CASE") &"', '" & request.QueryString("TOTAL_ESTIMATE_COST")&"')"

I always make it look more like:
Expand|Select|Wrap|Line Numbers
  1. objRS.addNew
  2. for each fld in objRS.fields
  3.    if request.QueryString(fld.name) <> "" then
  4.       objRS(fld.name) = request.QueryString(fld.name)
  5.    else
  6.       'supply a default value usually with some complex function if needed
  7.       objRS(fld.name) = supplyDefault(fld.name)
  8.    end if
  9. next
  10. objRS.update
  11.  
Of course you could always specify in your database that some fields are optional.

Jared
Mar 5 '07 #2

P: 3
But this is insert data to Access database I want to insert data to MS Sql database..How can I do this?

I did like:
if request.queryString <> "" then
query = "select FRAME_WORK_ARRANGEMENT_REF_NUM,TASK_TITLE from hamp6 where"

if request.queryString("FRAME_WORK_ARRANGEMENT_REF_NU M") <> "" then
query = query + " FRAME_WORK_ARRANGEMENT_REF_NUM like '" & replace(request.queryString("FRAME_WORK_ARRANGEMEN T_REF_NUM"), "'", "''") & "' and"
end if

but it is not working :(




***************************
I always make it look more like:
Expand|Select|Wrap|Line Numbers
  1. objRS.addNew
  2. for each fld in objRS.fields
  3.    if request.QueryString(fld.name) <> "" then
  4.       objRS(fld.name) = request.QueryString(fld.name)
  5.    else
  6.       'supply a default value usually with some complex function if needed
  7.       objRS(fld.name) = supplyDefault(fld.name)
  8.    end if
  9. next
  10. objRS.update
  11.  
Of course you could always specify in your database that some fields are optional.

Jared
Mar 6 '07 #3

jhardman
Expert 2.5K+
P: 3,405
But this is insert data to Access database I want to insert data to MS Sql database..How can I do this?
There is no difference between the way you access an MS Access db and a MS SQL Server db through an ASP. You will create an ADODB object, then use SQL statements to extract and manipulate the data.
I did like:
if request.queryString <> "" then
query = "select FRAME_WORK_ARRANGEMENT_REF_NUM,TASK_TITLE from hamp6 where"

if request.queryString("FRAME_WORK_ARRANGEMENT_REF_NU M") <> "" then
query = query + " FRAME_WORK_ARRANGEMENT_REF_NUM like '" & replace(request.queryString("FRAME_WORK_ARRANGEMEN T_REF_NUM"), "'", "''") & "' and"
end if

but it is not working :(
Try a quick experiment. Test the page in a way you think should work, but have a couple things written by the server. I would have the finished query statement and the original request queryString written right before executing the query:
Expand|Select|Wrap|Line Numbers
  1. response.write "<p>request('FRAME_WORK_ARRANGEMENT_REF_NUM'): " & request.queryString("FRAME_WORK_ARRANGEMENT_REF_NUM") & vbNewLine
  2. response.write "<p>Query: " & query & vbNewLine
  3.  
Do both of these have the right data that they should have? Let me know.

Jared
Mar 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.