Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have following code

C#
 OdbcCommand Command = MainClass.Conn.CreateCommand();
  Command.Connection = MainClass.Conn;
  
  using (OdbcTransaction transaction = MainClass.Conn.BeginTransaction())
            {
                Command.Transaction = transaction;
                try
                {
                    string saveStOpen = "Insert Statement.. "; \\ This This Is SQL Statement
                    Command.CommandText = saveStOpen;
                    Command.ExecuteNonQuery();

                    string saveGRNSub = "Insert Statement.."; \\ This This Is SQL 
                    Command.CommandText = saveGRNSub;
                    Command.ExecuteNonQuery();

                    OdbcCommand OpenTemp = new  OdbcCommand("SELECT * FROM GRN_TEMP WHERE (UserName = '" + MainClass.GetComputerName() + "')", MainClass.Conn);
                    OdbcDataAdapter da = new OdbcDataAdapter(OpenTemp);
                    DataTable dt = new DataTable();
                    da.Fill(dt); \\ This Point Genarate An Error 

                    if (dt.Rows.Count >0)
                    {
                        MessageBox.Show(dt.Rows.Count.ToString());
                    }
                    
                    
                    //}
                    //readTemp.Dispose();
                    
                    transaction.Commit();

at da.Fill(dt);
Generate Error (executereader requires the command to have a transaction )

how to avoid this error

I highly appreciate in advance
Posted
Updated 12-Nov-12 21:54pm
v3

You need to set the transaction after setting the connection object in command

Check this example
http://msdn.microsoft.com/en-us/library/2k2hy99x%28v=vs.71%29.aspx[^]
 
Share this answer
 
Open the Connection Before Filling the DataTable
 
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