string connectionString =""Data Source=192.168.0.3; User ID=sa; Password=; Initial Catalog=SunYatSite" ;
SqlConn = new SqlConnection(connectionString);
SqlCommand sqlComm = SqlConn.CreateCommand();
sqlComm.Connection=SqlConn;
sqlComm.CommandText="delete form table where id = '15'";
sqlComm.ExecuteNonQuery();
SqlConn.Close();
SqlConn = new SqlConnection(connectionString);
SqlCommand sqlComm = SqlConn.CreateCommand();
sqlComm.Connection=SqlConn;
sqlComm.CommandText="delete form table where id = '15'";
sqlComm.ExecuteNonQuery();
SqlConn.Close();
解决方案 »
- ASP.NET用GridView绑定数据源问题,VisualStudio2008使用问题,求助!在线等!
- 求正则!!!
- 要简单的打印浏览器内容的代码~!!!!!!!! 不需分页打印,也不需...... 只要简单的.有的把代码共享下下,谢谢
- 如何获得下拉框选中项的值
- 大侠指点一下 ajax中修改xml之后再读取xml 方法。
- 向项目中添加文件的时候出错,在线等
- 帮帮忙小弟,跨页面存值问题?
- 请问谁有关于xml当数据库的例子,要求能读,能写得!???多谢!!!!!!!!!!!!!!!!!!!!
- 想学asp.net,怎么安装vs.net?
- 想通过script控制IMAGE的width heigh的大小来实现鼠标移动到上面放大的作用为什么我的代码不能显示
- ◇◇◇关于数据类型转换的问题
- 我再看ASP.NET快速入门教程(装.NET自带的那个)时遇到了如下问题,请高手解答
要删除的编号,谢谢!
SqlConnection1.Open()
Dim comd1 As SqlCommand
comd1 = New SqlCommand("insert into zxjb(topic,text,message) values('" & text1.Text & "','" & text2.Text & "','" & text3.Text & "')", SqlConnection1)
comd1.ExecuteNonQuery()
SqlConnection1.Close()
sqlComm.CommandText="delete form table where id = '"+str+"'";
只要把這樣改一下就可以
sqlComm.CommandText("insert into zxjb(topic,text,message) values('" & text1.Text & "','" & text2.Text & "','" & text3.Text & "')",
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
<asp:Button id="button1" Text="刪除" CommandName="Delete"></asp:Button>
</Columns>
但还是实现不了,点击删除没有反映
非常感谢!
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
try
{
table=new DataTable();
if(!(IsPostBack))
Bindgrid();
}
catch
{
}
try
{
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q1";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q2";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q3";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q4";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q5";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q6";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
col=new DataColumn();
col.DataType=System.Type.GetType("System.String");
col.ColumnName="q7";
col.AutoIncrement=false;
col.Unique=false;
col.ReadOnly=false;
table.Columns.Add(col);
//***************************************************
DataGrid1.DataSource=table;
DataGrid1.DataBind(); }
catch
{
}
}
private DataTable table;
private DataColumn col;
private DataRow row; public void Bindgrid()
{
string sele1="select * from qw";
sqlConnection1.Open();
sqlSelectCommand1=new SqlCommand(sele1,sqlConnection1);
SqlDataReader reader=sqlSelectCommand1.ExecuteReader();
while(reader.Read())
{
row=table.NewRow();
row["q1"]=reader.GetString(0);
row["q2"]=reader.GetString(1);
row["q3"]=reader.GetString(2);
row["q4"]=reader.GetString(3);
row["q5"]=reader.GetString(4);
row["q6"]=reader.GetString(5);
row["q7"]=reader.GetString(6);
table.Rows.Add(row);
} DataGrid1.DataSource=table;
DataGrid1.DataBind();
reader.Close();
sqlConnection1.Close(); } private void Button1_Click(object sender, System.EventArgs e)
{
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.DataKeys[(int)e.Item.ItemIndex]; sqlCommand1.Connection.Open();
sqlCommand1.ExecuteNonQuery();
sqlCommand1.Connection.Close(); Bindgrid();
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 94px; POSITION: absolute; TOP: 47px" runat="server" Width="260px">
<Columns>
<asp:ButtonColumn Text="删除" HeaderText="wbbh" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 124px; POSITION: absolute; TOP: 235px" runat="server" Text="浏览"></asp:Button>
<asp:Button id="Button2" style="Z-INDEX: 103; LEFT: 340px; POSITION: absolute; TOP: 241px" runat="server" Text="删除" CommandName="delete"></asp:Button>
</form>
</body>
</HTML>
absolute; TOP: 47px" runat="server" Width="260px">里添加OnDeleteCommand="Button1_Click"
<asp:Button id="Button2" style="Z-INDEX: 103; LEFT: 340px; POSITION: absolute; TOP: 241px" runat="server" Text="删除" CommandName="delete"></asp:Button>
去掉试试
改為:public void DataGrid1_DeleteCommand(Object sender, DataGridCommandEventArgs e)
private void Page_Load(object sender, System.EventArgs e)
{
//页面javascript和隐含控件设置
Page.RegisterStartupScript("","<script> function SetuserValue(theValue) {document.all.theUser.value=theValue;} var obj = null;</script>");
Response.Write( @"<input type=hidden name='theUser'>" );
}private void MyDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ((int) e.Item.ItemIndex >=0 )
{ e.Item.Attributes["onclick"]=" SetuserValue('"+e.Item.Cells[0].Text+"'); if (obj == this) return; if (obj != null) obj.style.backgroundColor = ''; this.style.backgroundColor='#cccccc'; obj=this;";
e.Item.Attributes["onmouseover"]="javascript:this.bgColor='#FFDDAA'";
e.Item.Attributes["onmouseout"]="javascript:this.bgColor='#FFFFF5'";
}
}
sqlComm.CommandText="delete form table where id = '15'"; //form??
form是表单,应该是from吧!