int ScriptId = 0;
string sql = "Select Max(ScriptId) from tbl_Script";
SqlCommand cmd = new SqlCommand(sql, connection);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (reader["ScriptId"] == System.DBNull.Value)
{
ScriptId += 1;
}
else
{
ScriptId = ScriptId++;
}
}
}
globalScriptid = ScriptId.ToString();
SqlCommand cmd4 = new SqlCommand("tblScriptInsert", connection);
cmd4.Parameters.Add("@Ip_Address", SqlDbType.VarChar).Value = ScriptId.ToString();
cmd4.CommandType = CommandType.StoredProcedure;
this is my code i am i am get error in ( if (reader["ScriptId"] == System.DBNull.Value) IndexOutOfRangeException was unhandled pls help