Error when do a 'select'

I made a small program running on PDA to check data inside SQL Server database on the server.

When program runup, it will excutive 'SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'' to get all the table list. It runs successful.

After that I manaully key in a SQL(select * from station) in a text window and run it, then got error as below.
Any suggestion?
The C# project code also attached.

   at System.Data.SqlClient.TdsParser.SkipRow(_SqlMetaData[] columns, Int32 startCol)
   at System.Data.SqlClient.TdsParser.SkipRow(_SqlMetaData[] columns)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior run, SqlCommand cmdHandler, SqlDataReader dataStream)
   at System.Data.SqlClient.SqlDataReader.InternalClose(Boolean closeReader)
   at System.Data.SqlClient.SqlDataReader.Close()
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at Database_Connection.PDADataSetTableAdapters.StationTableAdapter.Fill(StationDataTable dataTable)
   at Database_Connection.Form1.Form1_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.Application.Run(Form fm)
   at Database_Connection.Program.Main()
turbot_yuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

momi_sabagCommented:
your c# code is not here but maybe you should try this instead

'SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = ''BASE TABLE'' '
turbot_yuAuthor Commented:
that one is ok, only the simple one not work, attached again.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
turbot_yuAuthor Commented:
namespace FW2WM5
{
    public partial class Form1 : Form
    {
        SqlConnection myConn;
        String connStr;

        public Form1()
        {
            InitializeComponent();
            connStr =
                @"Server='203.117.170.74';Database=PDA; User Id=x; Password=x";
        }

        private void button10_Click(object sender, EventArgs e)
        {
            try
            {
                myConn = new SqlConnection(connStr);
                myConn.Open();
                FillList();
            }

            catch (Exception ex)
            {
                MessageBox.Show("Connection error: " + ex.ToString());
            }

            finally
            {
                myConn.Close();
            }
        }

        private void FillList()
        {
            //SqlDataReader myDataReader;
            SqlDataAdapter myAdapter = new SqlDataAdapter(txtSQL.Text, myConn);
            DataSet myDataSet = new DataSet();
            myAdapter.Fill(myDataSet, "Result");
            // dataGridView1.DataSource = myDataSet.DefaultViewManager;
            dataGrid1.DataSource = myDataSet.Tables["Result"].DefaultView;

        }

        private void FillObject()
        {
            try
            {
                myConn = new SqlConnection(connStr);
                myConn.Open();
                SqlDataReader myDataReader;
                SqlCommand myCmd = myConn.CreateCommand();

                myCmd.CommandText = @"SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'";
                treeView1.BeginUpdate();
                treeView1.Nodes.Clear();
                treeView1.Nodes.Add(new TreeNode("Tables"));
                TreeNode childNode = treeView1.Nodes[0];

                int childCount = 0;
                myDataReader = myCmd.ExecuteReader();
                while (myDataReader.Read())
                {
                    string TableName = (myDataReader[0].ToString()) + "." + (myDataReader[1].ToString());
                    childNode.Nodes.Insert(childCount, new TreeNode(TableName));
                    childCount += 1;
                }
                myDataReader.Close();
                treeView1.Nodes.Add(new TreeNode("Views"));

                SqlCommand myCmdView = myConn.CreateCommand();
                myCmdView.CommandText = @"SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW'";
                TreeNode childNodeView = treeView1.Nodes[1];

                int childCountView = 0;

                myDataReader = myCmdView.ExecuteReader();
                while (myDataReader.Read())
                {
                    string ViewName = (myDataReader[0].ToString()) + "." + (myDataReader[1].ToString());
                    childNodeView.Nodes.Insert(childCount, new TreeNode(ViewName));
                    childCountView += 1;
                }

                myDataReader.Close();


                treeView1.ExpandAll();
                treeView1.EndUpdate();
                myConn.Close();
            } // try
            catch (SqlException myexception)
            {
                foreach (SqlError err in myexception.Errors)
                {
                    MessageBox.Show(err.Message);

                }

            } // catch

        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //if (PDADataSetUtil.DesignerUtil.IsRunTime())
            //{
                // TODO:  ddLãåûdpDADataSet.Station„ؤ AutoFill
                //this.stationTableAdapter.Fill(this.pDADataSet.Station);

            //}
            FillObject();

        }

        private void textBox2_Click(object sender, EventArgs e)
        {

        }

        private void txtSQL_TextChanged(object sender, EventArgs e)
        {

        }

        private void stationNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }


    }
}
int.jpg
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.