类型数据表typeTB结构:
id int 4
info vc 20文章数据表articleTB结构:
id int 4
tid int 4
topic vc 50
pic vc 50数据表typeTB记录:
id info
1 足球
2 娱乐
3 科技数据表articleTB记录:
id tid topic pic
1 2 2007影帝 1.gif,2.jpg
2 2 2007歌王 34.jpg
3 1 他中足采现有以上数据,当我在删除数据表typeTB中的id字段值等于2时的记录时,相应要删除数据表articleTB中tid字段值等于2的所有记录,包括记录相对应的图片文件。
如果在asp中,我可这样循还地做删除操作:
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * From typeTB where id=2"
rs.open sql,conn,3,2
if not rs.bof and not rs.eof then
Set rs1 = Server.CreateObject("ADODB.Recordset")
sql1 = "Select * From articleTB where tid="&rs("id")&""
rs1.open sql1,conn,3,2
tcount=rs1.RecordCount
if not rs1.bof and not rs1.eof then
for i=1 to tcount
id=rs1("id")
pic=rs1("pic")
//删除图片文件操作
conn.Execute "Delete From articleTB Where id="&id&" "
rs.movenext
if rs.eof then exit for
next
end if
rs1.close
end if
rs.close
conn.Execute "Delete From typeTB where id=2 "请问在C#中,是如何删除的呢,非常希望得到您的指教!!!有分时一定给!!!!!
id int 4
info vc 20文章数据表articleTB结构:
id int 4
tid int 4
topic vc 50
pic vc 50数据表typeTB记录:
id info
1 足球
2 娱乐
3 科技数据表articleTB记录:
id tid topic pic
1 2 2007影帝 1.gif,2.jpg
2 2 2007歌王 34.jpg
3 1 他中足采现有以上数据,当我在删除数据表typeTB中的id字段值等于2时的记录时,相应要删除数据表articleTB中tid字段值等于2的所有记录,包括记录相对应的图片文件。
如果在asp中,我可这样循还地做删除操作:
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * From typeTB where id=2"
rs.open sql,conn,3,2
if not rs.bof and not rs.eof then
Set rs1 = Server.CreateObject("ADODB.Recordset")
sql1 = "Select * From articleTB where tid="&rs("id")&""
rs1.open sql1,conn,3,2
tcount=rs1.RecordCount
if not rs1.bof and not rs1.eof then
for i=1 to tcount
id=rs1("id")
pic=rs1("pic")
//删除图片文件操作
conn.Execute "Delete From articleTB Where id="&id&" "
rs.movenext
if rs.eof then exit for
next
end if
rs1.close
end if
rs.close
conn.Execute "Delete From typeTB where id=2 "请问在C#中,是如何删除的呢,非常希望得到您的指教!!!有分时一定给!!!!!
解决方案 »
- 多重静态成员变量问题
- WPF的DataGrid如何支持方向键移动当前单元格?
- 有关数据库登录用户和密码问题
- form MDI问题
- 现有几个C#类,求高人做成DLL或COM组件给VC++或DELPHI调用(200分)急!!!!!!在线等
- 怎么动态判断控件得名字啊?谢谢大家
- 那位兄弟有ActivXe 的资料
- HttpWebRequest/HttpWebResponse 在ASP中用什么代替????
- 初学c# 定时器实在不知道为什么调刷新 items报异常
- 请问,很多软件都有一个About(就是 “关于”),是怎么做出来的?具体说说行不行?
- C#参数问题
- 关于字符串的近似匹配的问题,高手支招.谢谢.....在线等.
conn.ConnectionString = "Data Source= ;Initial Catalog= ;User ID= ;Password= ";
conn.Open();
string sql="delete from typeTB where id=2";
SqlCommand com = new SqlCommand(sql,conn);
com.ExecuteNonQuery();
conn.Close();
conn.ConnectionString = "Data Source=;Initial Catalog=;User ID=;Password=";
conn.Open();
string sql="select * from typeTB where id=2";
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(sql,conn);
da.SelectCommand = cmd;
da.Fill(ds,"typeTB");
for (int i = 0; i < ds.Tables["typeTB"].Rows.Count; i++)
{
string sql1 = "delete from articleTB where tid="+ds.Tables["typeTB"].Rows[i]["id"];
SqlCommand cmd1 = new SqlCommand(sql1,conn);
cmd1.ExecuteNonQuery();
}
SqlCommand cmd2 = new SqlCommand("delete from typeTB where id=2", conn);
cmd2.ExecuteNonQuery();
conn.Close();
create or replace deleteRecord (count in int) is
begin
delete from typeTB where id=count;
delete from articleTB where id=count;
end deleteRecord;
因我对存储过程不懂呀,麻烦您帮我写详细些好没?谢谢!!!
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source= ;Initial Catalog= ;User ID= ;Password= ";
conn.Open();
string sql="delete from typeTB where id=2 delete from articleTB where tid =2";
SqlCommand com = new SqlCommand(sql,conn);
com.ExecuteNonQuery();
conn.Close();
as
set @pics=''
select @pics=@pics+','+pic from articleTB
where tid=@id
set @pics=stuff(@pics,1,1,'')以下是执行语句:
declare @pics varchar(8000)
EXEC aa 2,@pics output
select @pics 谢谢所以帮忙的朋友!!!