my code is
private int GetNextStudentID()
{
command.CommandText = "SELECT IDENT_CURRENT ('admn') + IDENT_INCR ('admn')";
try
{
connection.Open();
int nextID = Convert.ToInt32(command.ExecuteScalar());// here i am getting error
return nextID;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
return 0;
}

Ravi PatelRank #439 · 5.7K reputationPosted Dec 19, 2015, 1:09 AM EST
{
command.CommandText = "SELECT IDENT_CURRENT ('admn') + IDENT_INCR ('admn')";
try
{
connection.Open();
var nextID = command.ExecuteScalar();
if(!(nextID is DBNull))
{
nextID = Convert.ToInt32(nextID);
}
return nextID;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
return 0;
}
raju m3 reputationPosted Dec 19, 2015, 1:49 AM EST
{
command.CommandText = "SELECT IDENT_CURRENT ('admn') + IDENT_INCR ('admn')";
try
{
connection.Open();
var nextID = command.ExecuteScalar();
if(!(nextID is DBNull))
{
nextID = Convert.ToInt32(nextID);
}
return nextID; // here i an getting error like this
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
return 0;
}