看我有这个代码:
private void obtengoUltimoComienzoColocado()
{
ManejoUsuarios lAdm = new ManejoUsuarios();
lblTodoOK.Text = lAdm.LevantoUltimoIDBarco().ToString();
}
public int LevantoUltimoIDBarco()
{
ConexionBD lP = new ConexionBD();
try
{
string lQuery = "Select Max(idBarco) as UltimoID From Comienzos;";
Convert.ToInt32(lP.ObtenerRegistro(lQuery));
return 1;
}
catch (Exception ex)
{
return 0;
}
}
public DataSet ObtenerRegistro(string SqlQuery)
{
DataSet lResult;
SqlConnection lSqlConnection = new SqlConnection("Data Source=SEBA-PC\\sqlexpress;Initial Catalog=Batalla_Naval;Integrated Security=True");
SqlCommand lSqlCommand = null;
try
{
lSqlCommand = new SqlCommand();
lSqlCommand.CommandText = SqlQuery;
lSqlCommand.CommandType = CommandType.Text;
SqlDataAdapter lAdapter = new SqlDataAdapter(lSqlCommand);
lResult = new DataSet();
lSqlConnection.Open();
lSqlCommand.Connection = lSqlConnection;
lAdapter.Fill(lResult);
}
catch (Exception)
{
throw;
}
finally
{
lSqlConnection.Close();
}
return lResult;
}
如您所见,我使用三个函数进入数据库并从表 Comienzos 中获取最大 ID,但是当我想将数据集转换为 int32 时,函数 LevantoUltimoIDBarco 返回我 0,