Solved

Mysql Query in ASP.NET

Posted on 2011-09-21
3
267 Views
Last Modified: 2012-05-12
Hi all,
I am converting some codes from PHP to C#. The data from the php are in msql. I have managed to connect to the database from the .Net code.

I now have the insert statement below from the php code. How do I replace the php variables with my C# ones.

At the moment, I have some string variables eg.
string pcn = Request.QueryString["pcn"];
            string vrm = Request.QueryString["vrm"];
            string amt = Request.QueryString["amt"];

that I will like to put in place of the php variables.

I have used this :
string sSQL=" INSERT INTO capitapayment(fundcode,fundname,ref,amt,source,rurl,backurl,vatcode,custemail,reconscript,sysref,`when`,`live`) VALUES ('31',' Charge Notice','" + pcn + "','" + amt +" ','I ',' www.mycoy.uk ',' www.mycoy.uk ',' F ','','','"+pcn+"',NOW(), 1)";

but it's inserting a null value in the table.
$sql = "INSERT INTO capitapayment(fundcode,fundname,ref,amt,source,rurl,backurl,vatcode,custemail,reconscript,sysref,`when`,`live`) VALUES ('" . mysql_escape_string ($fundcode) . "','" . mysql_escape_string ($fundname) . "','" . mysql_escape_string ($ref) . "','" . mysql_escape_string ($amt) . "','" . mysql_escape_string ($source) . "','" . mysql_escape_string ($returnurl) . "','" . mysql_escape_string ($backurl) . "','" . mysql_escape_string ($vatcode) . "','" . mysql_escape_string ($custemail) . "','" . mysql_escape_string ($reconscript) . "','" . mysql_escape_string ($sysref) . "',NOW()," . CONST_CAPITA_LIVE . ")";

Open in new window

0
Comment
Question by:olootu
3 Comments
 
LVL 6

Accepted Solution

by:
Triskelion earned 250 total points
ID: 36578045
Are you sure those variables are NOT NULL when being inserted?
Are they actually coming back from the query string?
0
 
LVL 4

Expert Comment

by:Fugas
ID: 36578953
What are values of your variables you are trying to insert?
0
 

Author Closing Comment

by:olootu
ID: 36579071
You are right! The variables were actually NULL when I inserted them into the DB. I have corrected  it and it's working fine now. Many thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question