Solved

Mysql Query in ASP.NET

Posted on 2011-09-21
3
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

690 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