Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am writing a code for a SQL 'Interpreter. There is an error with Items which I highlighted below. The error message: 'TextBox' does not

I am writing a code for a "SQL 'Interpreter".

There is an error with "Items" which I highlighted below.

The error message: 'TextBox' does not contain a definition for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'TextBox' could be found (are you missing a using directive or an assembly reference?)

Please be specific on how to fix it, thank you!

private void Click_Run_Click(object sender, EventArgs e) //run button { try { string Buffer = System.IO.File.ReadAllText(textBox1.Text);

string[] sql_commands = Buffer.Split(new char[] { ';' });

string ConnectString = "provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + textBox2.Text;

System.Data.OleDb.OleDbConnection Connection = new System.Data.OleDb.OleDbConnection(ConnectString);

System.Data.OleDb.OleDbCommand SQLCommand = null;

Connection.Open(); // open the connection

for (int i = 0; i < sql_commands.Length - 1; i++) { textBox3.Items.Add(sql_commands[i] );

try { // make a SQL command from the query SQLCommand = new System.Data.OleDb.OleDbCommand(sql_commands[i], Connection);

SQLCommand.ExecuteNonQuery(); } catch (Exception) // error message when the user try to upload a invalid SQL query to database { MessageBox.Show("Error sending to database"); return; } }

Connection.Close(); // now the connection closed } catch (Exception) { MessageBox.Show("Error, No file selected"); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions