Solved

Mysql Query in ASP.NET

Posted on 2011-09-21
3
265 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now