看看我有這樣的代碼:轉換數據集到整數
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功能,
謝謝!我在哪裏插入代碼? – Spresno
如果你有這樣的代碼:'Convert.ToInt32(lP.ObtenerRegistro(lQuery));' – Raidri
真的有用,我做到了!謝謝! – Spresno