我的问题都已经好几天,还未解决?
请各位高手帮我检查代码的错误。谢谢!
public void DataGrid1_Delete(Object sender, DataGridCommandEventArgs e)
{
string deleteCmd = "DELETE from qw where q1 = @q1";
SqlCommand sqlCommand1 = new SqlCommand(deleteCmd,sqlConnection1);
sqlCommand1.Parameters.Add(new SqlParameter("@q1", SqlDbType.Char, 6));
sqlCommand1.Parameters["@q1"].Value =DataGrid1.DataKeys[(int)e.Item.ItemIndex];
sqlCommand1.Connection.Open();
sqlCommand1.ExecuteNonQuery();
sqlCommand1.Connection.Close();
Bindgrid();
}//public void DataGrid1_Delete(Object sender, DataGridCommandEventArgs e)
//string deleteCmd = "DELETE from qw where q1=@q1 ";
//SqlCommand sqlCommand1 = new SqlCommand(deleteCmd, sqlConnection1);
//sqlCommand1.Parameters.Add(new SqlParameter("@q1", SqlDbType.Char,6));
//sqlCommand1.Parameters["@q1"].Value = DataGrid1.Columns .ToString ();
//sqlCommand1.Connection.Open();
//int id=DataGrid1.SelectedIndex;
//string q11=this.DataGrid1.DataKeys[(int)id+1].ToString();
//.Item.Cells[1].Text;
//string sqlstr="delete from qw where q1="+"'"+q11+"'";
//sqlConnection1.Open();
//System.Data.SqlClient.SqlCommand sqlDeleteCommand2=new System.Data.SqlClient.SqlCommand(sqlstr,sqlConnection1);
//sqlDeleteCommand2.ExecuteNonQuery();
//sqlConnection1.Close();
//String deleteCmd = "DELETE FROM qw WHERE q1 d='"+datagrid.DataKeys[i].ToString()+"'";
//SqlCommand sqlCommand1 = new SqlCommand(deleteCmd, sqlConnection1);
//sqlCommand1.Parameters.Add(new SqlParameter("@q1",
//sqlDbType.Char, 6));
// Initialize the SqlCommand "@Id" parameter to the ID of the row
// that was clicked.
//sqlCommand1.Parameters["@q1"].Value =
//DataGrid1.DataKeys[(int)e.Item.ItemIndex];
// Connect to the database and delete the specified row.
//sqlCommand1.Connection.Open();
// Test whether the delete was accomplished and display the
// appropriate message to the user.
//sqlCommand1.ExecuteNonQuery();
//private void Button5_click(object sender, System.Web.UI.WebControls.DataGridCommand.EventArgs e)
//this. sqlDeleteCommand2.Parameters["@q1"].Value=this.TextBox5.Text.ToString();
//string sqlstr="delete from qw where q1=@q1";
//sqlConnection1.Open();
//System.Data.SqlClient.SqlCommand sqlDeleteCommand2=new System.Data.SqlClient.SqlCommand(sqlstr,sqlConnection1);
//sqlDeleteCommand2.ExecuteNonQuery();
//sqlConnection1.Close();
//private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
// int delRow=e.Item.ItemIndex; //获取删除列
// this.dataSet11.q1.Rows[delRow].Delete();//在数据集中删除数据
// this.sqlDataAdapter1.Update(this.dataSet11);//将数据集更改提交到数据库
// this.DataGrid1.DataBind();//刷新DataGrid