如何将两个MySQL id传递给c#.exe?

I am trying to make a PDF form filling program. The program should get 2 id's from the PHP script, search the MySQL database, and fill the forms with info based of those two id's, but i cant make the PHP script pass arguments to the c# executable. Maybe u can help me out :)

PHP script :

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("documente", $con);

$idfirma;
$idagent;

$sql="SELECT * FROM `agenti` WHERE `Nume Agent` = '$_GET[numea]'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "Date agent"."<br>";
echo $row['Nume Agent'];echo "    |     ";echo $row['Sigiliu'];echo "    |     ";echo $row['Legitimatie']."<br>"."<br>"."<br>"."<br>"."<br>";
$idagent=$row['ID'];
}

$sql1="SELECT * FROM `dateclienti` WHERE `Cod Fiscal` = '$_GET[codf]'";
$result = mysql_query($sql1);
while($row = mysql_fetch_array($result)) {
echo "Date Firma"."<br>";
echo $row['Nume Societate'];echo "    |     ";echo $row['Adresa Sediu'];echo "    |     ";echo $row['Cod Fiscal']."<br>";
$idfirma=$row['ID'];
}



exec("pdfgen\PdfGenerator\bin\Debug\PdfGenerator.exe $idfirma, $idagent 2>&1");
echo $idfirma."<br>"."<br>";
echo $idagent;



if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }




mysql_close($con)
?>

c# scipt :

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
using System.IO;
using MySql.Data.MySqlClient;




namespace PdfGenerator
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            FillForm();
            ListFieldNames();
        }


        /// <summary>
        /// List all of the form fields into a textbox.  The
        /// form fields identified can be used to map each of the
        /// fields in a PDF.
        /// </summary>
      private void ListFieldNames()


       {
              string pdfTemplate = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\form.pdf";

              // title the form
              this.Text += " - " + pdfTemplate;

              // create a new PDF reader based on the PDF template document
              PdfReader pdfReader = new PdfReader(pdfTemplate);

              // create and populate a string builder with each of the 
              // field names available in the subject PDF
              StringBuilder sb = new StringBuilder();
              foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
              {
                  sb.Append(de.Key.ToString() + Environment.NewLine);
              }

              // Write the string builder's content to the form's textbox
              textBox1.Text = sb.ToString();
              textBox1.SelectionStart = 0;
          }



         private void FillForm()
        {
            string idagent1 = null;
            string idfirma1 = null;
            string[] args = System.Environment.GetCommandLineArgs();
            if(args.Length !=0)
            {
                idfirma1 = args[1];
                idagent1 = args[2];

            }


                using (var connection = new MySqlConnection("server = localhost; User Id = root; password = ; database = documente;"))
            {


                connection.Open();


                string agenti = "SELECT `Nume Agent` FROM `agenti` WHERE `ID` = @id";
                string name1 = null;

                using (var cmd = new MySqlCommand(agenti, connection))
                {
                    cmd.Parameters.AddWithValue("@id", idagent1);
                    MySqlDataReader rdr = cmd.ExecuteReader();
                    DataTable dt = new DataTable();
                    dt.Load(rdr);

                    foreach (DataRow row in dt.Rows)
                    {
                        string name = row["Nume Agent"].ToString();

                        name1 = name;
                    }






















                    string pdfTemplate = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\form.pdf";
                    string newFile = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\completed_form.pdf";

                    PdfReader pdfReader = new PdfReader(pdfTemplate);
                    PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
                                newFile, FileMode.Create));

                    AcroFields pdfFormFields = pdfStamper.AcroFields;

                    // set form pdfFormFields

                    // The first worksheet and W-4 form
                    pdfFormFields.SetField("topmostSubform[0].Page1[0].regcomert[0]", name1);




                    // flatten the form to remove editting options, set it to false
                    // to leave the form open to subsequent manual edits
                    pdfStamper.FormFlattening = true;

                    // close the pdf
                    pdfStamper.Close();

                }
            }



        }
    }
}










using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace PdfGenerator
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
dongliang9576
dongliang9576 它仅供我个人使用,我只测试一些东西。我能忍受。
大约 3 年之前 回复
doy51723
doy51723 您应该使用mysqli而不是mysql,并且您很容易受到SQL注入攻击。
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问