Click here to Skip to main content
15,886,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello people.

My first foray into MySQL after Ms Sql.

In C# and MySQL, I get results when I execute this method so no problem.

C#
public DataTable SupplierPeople(String pSupplierId)
{
    String cmd = "Select perName As `Name`, speDesignation As `Designation`, speId As `SysId` From main.SupplierPeople Inner Join main.People On spePerId = perId Where speSupId = " + pSupplierId + ";";
    DataTable dat = new DataTable();
    dl = new DataLayer(cmd);
    if (dl.ConnectToServer())
    {
        dat = dl.ExecuteFillDataTable();
        dl.CloseConnection();
    }
    return dat;
}


But I need the serial number there so I put in somethings before the "Select" and it gives me an error "Fatal error encountered during command execution."

C#
public DataTable SupplierPeople(String pSupplierId)
     {
         String cmd = "set @rn=0;Select @rn:=@rn+1 As `Sno`, perName As `Name`, speDesignation As `Designation`, speId As `SysId` From main.SupplierPeople Inner Join main.people On spePerId = perId Where speSupId = " + pSupplierId + ";";
         DataTable dat = new DataTable();
         dl = new DataLayer(cmd);
         if (dl.ConnectToServer())
         {
             dat = dl.ExecuteFillDataTable();
             dl.CloseConnection();
         }
         return dat;
     }


I tried running the cmd (capturing it at runtime) in Workbench and it works fine but not in C# program. Fyi, it's a Windows application.

Please help. Thank you.
Posted
Updated 17-Jan-16 21:22pm
v2
Comments
_Asif_ 18-Jan-16 3:29am    
Try Debugging the code by using this query. Select 1 As `Sno`, perName As `Name`, speDesignation As `Designation`, speId As `SysId` From main.SupplierPeople Inner Join main.people On spePerId = perId Where speSupId = pSupplierId
Zakirom 18-Jan-16 3:34am    
Select 1 As `Sno`, perName As `Name`, perMobile As `Mobile`, perEmail As `Email`, speDesignation As `Designation`, speId As `SysId` From Shahab.SupplierPeople Inner Join Shahab.People On spePerId = perId Where speSupId = 7;

That works fine but all turns out as 1
_Asif_ 18-Jan-16 3:36am    
Would not @rn=0; Select @rn+1 will always turn out 1 also?
Zakirom 18-Jan-16 3:40am    
Its Select @rn:=@rn+1
_Asif_ 18-Jan-16 3:51am    
You are not thinking! Points to ponder!
* Where have you declare the @rn? what is its type?
* SET @rn=0; SELECT @rn = @rn + 1 will always return 1! Why?
* Why have not you used AUTO_INCREMENT?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900