我在删除gridview时遇到问题。我有带有Id,Name,Address,Phone的表名Doctor。Id是自动生成的字段。在我在gridview中显示时添加数据后,如果再次从gridview中删除任何id,那么如果我添加任何新的表格中的详细信息从新数字开始。我的意思是,如果我删除最后一个 id 号 5,那么如果我添加任何新医生,它的 id 值 6 而不是从 5 开始。我的查询是它应该从 5 重新开始。这里是我的代码。请帮助我。
public class Doctor
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
}
public static class DoctorDataLayer
{
public static void AddDoctor(Doctor doctor)
{
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; // JohannesH: Changed from .ToString() to .ConnectionString
using(var connection = new SqlConnection(connectionString))
{
using (var command = new SqlCommand("insert into doctor values(@name,@address,@phone)", connection))
{
command.Parameters.AddWithValue("@name", doctor.Name);
command.Parameters.AddWithValue("@address", doctor.Address);
command.Parameters.AddWithValue("@phone", doctor.Phone);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
}
}
}
public static class DoctorBusinessLayer
{
public static void CreateDoctor(string name, string address, string phone)
{
DoctorDataLayer.AddDoctor(new Doctor {Name = name, Address = address, Phone = phone});
}
}