我需要根据作为唯一标识符的 id 从 gridview 和数据库中删除一行。在我下面的代码中,我收到错误消息“无法识别的 Guid 格式”。有什么帮助可以解决吗?
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.Rows[e.RowIndex].Cells[0].Text;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand("Delete", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@ID", SqlDbType.UniqueIdentifier);
command.Parameters["@ID"].Value = new System.Guid(id);
command.Connection.Open();
command.ExecuteNonQuery();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
command.Connection.Close();
}