Click here to Skip to main content
15,920,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public DataSet GetAllActiveTraining(int CompanyId)
        {
            try
            {
                SqlConnection conn = new SqlConnection(objConnection.GetConnection());
                DataSet DsLoginData = new DataSet();
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn, CommandType.Text, "Select a.DocumentId,a.Title form [dbo].[Document] AS a inner join [dbo].[companydocument] AS b on (a.DocumentId=b.DocumentId) where a.hastest=1 and b.CompanyId=" + CompanyId + "order by a.Title ASC");
                DsLoginData.Tables[0].TableName = "trainingmodule";

                return DsLoginData;

            }
            catch (Exception)
            {

                throw;
            }
        }
Posted
Updated 22-Jul-15 23:49pm
v2

It's because of a small typo- FORM instead of FROM
Try this-
C#
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn, CommandType.Text, "Select a.DocumentId,a.Title FROM [dbo].[Document] AS a inner join [dbo].[companydocument] AS b on (a.DocumentId=b.DocumentId) where a.hastest=1 and b.CompanyId=" + CompanyId + " order by a.Title ASC");


Hope, it helps :)
 
Share this answer
 
v2
Comments
Sambit_Sahoo 23-Jul-15 5:54am    
Yes bro,thanks a lot
Suvendu Shekhar Giri 23-Jul-15 5:56am    
Glad to know that it helped :)
Wendelius 23-Jul-15 6:00am    
Exactly, +5
one mistake is using FORM instead of FROM, and b.CompanyId=" + CompanyId + "order by a.Title ASC also may throw exceptions becouse you haven't add space after companyId, it should be b.CompanyId=" + CompanyId + " order by a.Title ASC
 
Share this answer
 
Comments
Wendelius 23-Jul-15 6:00am    
Good point, 5
There are a few things to fix. As already pointed out you have a spelling mistake: FORM should be FROM
Another thing is that you concatenate values directly to the SQL statement. Don't do this. It leaves you open for SQL injection and may easily cause problems in data type conversions. Instead use SqlParameter[^]
 
Share this answer
 
Comments
DamithSL 23-Jul-15 5:54am    
5wd
Wendelius 23-Jul-15 6:00am    
Thanks :)
Hi Check select query "form" or "from" ? sql got "form"
C#
DsLoginData = SqlHelper.SqlHelper.ExecuteDataset(conn, CommandType.Text, "Select a.DocumentId,a.Title form [dbo].[Document] AS a inner join [dbo].[companydocument] AS b on (a.DocumentId=b.DocumentId) where a.hastest=1 and b.CompanyId=" + CompanyId + "order by a.Title ASC");


Regards
Aravind
 
Share this answer
 
v2
Comments
Sambit_Sahoo 23-Jul-15 5:54am    
Yes bro,thanks a lot
Aravindba 23-Jul-15 6:01am    
u r welcome,if we get error like this,just use break point and trace sql string,just copy that SQL query with values and manually execute in sql server management studio.

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