My code:
public void FillMaxBankCode()
{
try
{
DataSet ds = new DataSet();
ds = bol.SelectMaxBankCode();
string j = ds.Tables[0].
int.Parse(..)
is for converting a string containing digits into an integer. You are trying to perform the function int.Parse(..)
on a string but then assign it to another string. That won't work because int.Parse(..)
returns and integer. Read here about Int32.Parse (String) method.
txtbankid.Text
property type is a string. Don't use int.parse
. There is no need to. Just do: txtbankid.Text = j;
public void FillMaxBankCode()
{
try
{
DataSet ds = new DataSet();
ds = bol.SelectMaxBankCode();
string j = ds.Tables[0].Rows[0].ToString();
txtbankid.Text = j;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
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();
}