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 PatelPosted Dec 19, 2015, 6:09 AM
{
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 mPosted Dec 19, 2015, 6:49 AM
{
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;
}