Solved

Mysql Query in ASP.NET

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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