I'm new to C# so this is quite a noobie question; how would I reference variable OEint in my SQLCOMMAND method
Error: The name 'OEint' does not exist in the current context
If there are some good docs out there that go into detail on C# referencing, I would love if you could provide links.
Thank you in advance
void OE()
{
String OE = comboBox1.SelectedItem.ToString();
if (OE == "Yes")
{
int OEint = 1;
}
else if (OE == "No")
{
int OEint = 0;
}
else if (OE == "OLO only")
{
int OEint = -1;
}
}
void SQLCOMMAND()
{
try
{
String u_conn_input = textBox1.Text;
String conn_string = @"Server=.\" @u_conn_input ";Database=Test1;User Id=Test;Password=Test;Timeout=5;";
SqlConnection con = new SqlConnection(conn_string);
SqlCommand command = new SqlCommand("update test1..coupons2 set oe=" OEint "where [Coupon Code]=\'" textBox2.Text "\'", con);
con.Open();
command.ExecuteNonQuery();
textBox3.Text = textBox3.Text "Coupon Updated" Environment.NewLine;
MessageBox.Show(comboBox1.SelectedItem.ToString());
}
catch (SqlException)
{
textBox3.Text = textBox3.Text "Coupon Update Failed" Environment.NewLine;
}
}
CodePudding user response:
Error: The name 'OEint' does not exist in the current context
Because each block has its own scope, "visibility" so to speak. You could share this variable by either passing it as a parameter or by defining it in a global/bigger/containing scope.