Cannot implicitly convert type 'int' to 'string'

前端 未结 4 1177
情话喂你
情话喂你 2021-01-28 01:26

My code:

public void FillMaxBankCode()
{
    try
    {
        DataSet ds = new DataSet();
        ds = bol.SelectMaxBankCode();
        string j = ds.Tables[0].         


        
4条回答
  •  醉话见心
    2021-01-28 01:50

    If you want to ensure that the value is an integer before assigning it I suggest you use TryParse

    // check if the table and row exists
    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
    {
        string j = ds.Tables[0].Rows[0].ToString();
        int value = 0;
        if (int.TryParse(j, out value))
            txtbankid.Text = value.ToString();
    }
    

提交回复
热议问题