C# SQL Select using where as variable
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.
Subject
Written By
Posted
C# SQL Select using where as variable
December 18, 2012 01:38PM
December 18, 2012 06:01PM
December 18, 2012 09:23PM
December 19, 2012 01:13PM
December 19, 2012 05:49PM
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.