如果Else Statement为两个不同的用户 [英] If Else Statement for two different users

查看:88
本文介绍了如果Else Statement为两个不同的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Textbox_TextChanged事件,其代码将分割输入的数字。在同一个TextChange中,我有数学代码来查看用户是学期用户还是季度用户。在数学代码中,如果用户是学期用户,则它将除以特定数字。如果用户是季度用户,则它将除以另一个特定数字。我需要另外一双眼睛来查看代码是否正常。它不适合我。有人可以告诉我,如果我错过了某些内容或使用IF,Else声明错了吗?



  protected   void  TextBoxNCC_TextChanged( object  sender,EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ PasswordConnectionString]的ConnectionString);
con.Open();

if true
{
SqlCommand level = new SqlCommand( 从TableCOCINST中选择INST_ID,日历其中INST_ID =' + TextBoxINST_ID.Text + ',con);
level.Parameters.Add( new SqlParameter( INST_ID,TextBoxINST_ID.Text));
level.Parameters.Add( new SqlParameter( 日历,TextBoxINST_ID.Text));

SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(读者);

foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1 [ 0 ]。ToString());
int inst_id = Convert.ToInt32(dr1 [ 2 ]。ToString());
会话[ inst_id] = inst_id;

if (returnedLevel == Semester)
{
int i = Convert.ToInt32(TextBoxNCC.Text);
int j = 168 ;
TextBoxNCCDR.Text = Convert.ToString(i / j);

}
else if (returnedLevel == Quarter)
{
int i = Convert.ToInt32(TextBoxNCC.Text);
int j = 120 ;
TextBoxNCCDR.Text = Convert.ToString(i / j);
}
}

解决方案

如果从DB获取字符串值,则必须更改为字符串



  string  returnedLevel =(dr1 [ 0 ]。ToString()); 





你必须在比较时放入这个



  if (returnedLevel ==  学期
{
int i =转换.ToInt32(TextBoxNCC.Text);
int j = 168 ;
TextBoxNCCDR.Text = Convert.ToString(i / j);

}
else if (returnedLevel == Quarter
{
int i = Convert.ToInt32(TextBoxNCC.Text);
int j = 120 ;
TextBoxNCCDR.Text = Convert.ToString(i / j);
}







或者如果是int,

你必须在声明变量时分配一个值

I have a a Textbox_TextChanged Event with a code that will divide the number being entered. In that same TextChange I have the math code to see if the user is a Semester User or Quarter User. In the math code if the user is a Semester User it will divide be a certain number. If the user is a Quarter User it will divide by another certain number. I need another pare of eyes to look and see if the code looks ok. It is not working on my side. Can someone tell me if I have missed something or useing the IF,Else statement wrong?

protected void TextBoxNCC_TextChanged(object sender, EventArgs e)
   {
       SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        if (true)
        {
            SqlCommand level = new SqlCommand("Select INST_ID, Calendar from TableCOCINST where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
            level.Parameters.Add(new SqlParameter("INST_ID", TextBoxINST_ID.Text));
            level.Parameters.Add(new SqlParameter("Calendar", TextBoxINST_ID.Text));

            SqlDataReader reader = level.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);

            foreach (DataRow dr1 in dt1.Rows)
            {
                int returnedLevel = Convert.ToInt32(dr1[0].ToString());
                int inst_id = Convert.ToInt32(dr1[2].ToString());
                Session["inst_id"] = inst_id;
                    
                if (returnedLevel == Semester)
                {
                    int i = Convert.ToInt32(TextBoxNCC.Text);
                    int j = 168;
                    TextBoxNCCDR.Text = Convert.ToString(i / j);

                }
                else if (returnedLevel == Quarter)
                {
                    int i = Convert.ToInt32(TextBoxNCC.Text);
                    int j = 120;
                    TextBoxNCCDR.Text = Convert.ToString(i / j);
                }
   }

解决方案

If you get string value from DB.You have to change into string

string returnedLevel = (dr1[0].ToString());



you have to put "" while compare.try this

if (returnedLevel == "Semester")
{
   int i = Convert.ToInt32(TextBoxNCC.Text);
   int j = 168;
   TextBoxNCCDR.Text = Convert.ToString(i / j);

}
else if (returnedLevel == "Quarter")
{
   int i = Convert.ToInt32(TextBoxNCC.Text);
   int j = 120;
   TextBoxNCCDR.Text = Convert.ToString(i / j);
}




or if it is int,
you have to assign a value while declaring variable


这篇关于如果Else Statement为两个不同的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆