?
Solved

Mysql Query in ASP.NET

Posted on 2011-09-21
3
Medium Priority
?
274 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 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