我需要從gridview和數據庫中刪除一行,這是基於它的唯一標識符的id。 在我的代碼下面我得到錯誤味精「無法識別的Guid格式」。任何幫助解決它?如何處理asp.net中的唯一標識符參數
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();
}
我試過你的,但沒有運氣仍然是一樣的錯誤msg – newuser1555
string id = GridView1.Rows [e.RowIndex] .Cells [0] .Text; Guid myid = new Guid(id); System.Data.SqlTypes.SqlGuid theSqlGuid = new System.Data.SqlTypes.SqlGuid(myid); – newuser1555