Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.14/5 (3 votes)
See more:
C#
public void GetData()
{
    try
    {
        cc.con = new SqlConnection(cs.DBCon);
        cc.con.Open();
        cc.cmd = new SqlCommand("Select RTRIM(Pay_ID),RTRIM(PaymentID) from Procedure order by PaymentID", cc.con);
        cc.rdr = cc.cmd.ExecuteReader(CommandBehavior.CloseConnection); Procedure order by PaymentID", cc.con);
        dataGridView1.Rows.Clear();
        while (cc.rdr.Read())
        {
            dataGridView1.Rows.Add(cc.rdr[0], cc.rdr[1], cc.rdr[2]);
        }
        cc.con.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
    }
}


What I have tried:

incorrect syntax near the keyword Procedure
Posted
Updated 27-Jul-16 7:41am
v2
Comments
[no name] 27-Jul-16 11:04am    
Wat is this?
cc.rdr = cc.cmd.ExecuteReader(CommandBehavior.CloseConnection);Procedure order by PaymentID", cc.con);
Leo Chapiro 27-Jul-16 11:22am    
That was possibly Copy&Paste error: in the row above stays the same ... I've marked the question as unclear/incomplete.
[no name] 27-Jul-16 11:49am    
Thanks for the hint.

The name PROCEDURE is a reserved keyword[^] in SQL. You will need to enclose the name in square brackets to use it:
SQL
Select RTRIM(Pay_ID),RTRIM(PaymentID) from [Procedure] order by PaymentID
 
Share this answer
 
Try Below Code

C#
public void GetData()
{
    try
    {
        cc.con = new SqlConnection(cs.DBCon);
        cc.con.Open();
        cc.cmd = new SqlCommand("Select RTRIM(Pay_ID),RTRIM(PaymentID) from Procedure order by PaymentID", cc.con);
        cc.rdr = cc.cmd.ExecuteReader(); // Changed Here
        dataGridView1.Rows.Clear();
        while (cc.rdr.Read())
        {
            dataGridView1.Rows.Add(cc.rdr[0], cc.rdr[1], cc.rdr[2]);
        }
        cc.con.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
    }
}
 
Share this answer
 

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