C# SQL Select using where as variable
Posted by: Ajay Baldeo
Date: December 18, 2012 01:38PM

Hi All,

I'm new to working with SQL and I'm not writing this select statement properly because it's caught as an Exception.

string commandText = "select weight" +
"from inv" +
"where item_num = @inumber";

cmd = connection.CreateCommand();
cmd.CommandText = commandText;
cmd.Parameters.AddWithValue("@inumber", txt_item1.Text);
try
{
connection.Open();
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
MessageBox.Show(rdr["weight"].ToString());
}
rdr.Close();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}

This is not the end purpose of the db read but a way of testing my syntax and progress.



Edited 2 time(s). Last edit at 12/18/2012 02:30PM by Ajay Baldeo.

Options: ReplyQuote


Subject
Written By
Posted
C# SQL Select using where as variable
December 18, 2012 01:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.