积极答复者
数据库删除问题

问题
-
if (dataGridView1.CurrentCell!= null) { string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JoblD not in (select distinct Table2.JobName from Table3 inner join Table2 on Table3.JobName = Table2.JobName)"; SqlCommand com=new SqlCommand (str,con); SqlDataReader dr; dr = com.ExecuteReader(); if (!dr.Read()) { MessageBox.Show("删除工种'" + ds.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString().Trim() + "'失败,请先删除与此工种的相关员工", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dr.Close(); } }
- 已编辑 heiye178 2011年9月3日 4:57
答案
-
请仔细看我下划线加粗的部分!
string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JoblD not in (select distinct Table2.JobName from Table3 inner join Table2 on Table3.JobName = Table2.JobName)";
你怎么可以把jobId和JobName相比较呢?
建议把第二个下划线部分改成:
Table2.JobId
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 Dummy yoyoModerator 2011年9月9日 2:39
-
因为JoblD类型为int,JobName类型为nvarchar
- string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JoblD not in (select distinct Table2.JobID from Table3 inner join Table2 on Table3.JobName = Table2.JobName)";
- string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JobName not in (select distinct Table2.JobName from Table3 inner join Table2 on Table3.JobName = Table2.JobName)";
看需求,请自取一个
另外,好像没看到有Delete语句(似乎不太符合题意?)
Shadowと愉快なコード達
- 已编辑 Shadow .Net 2011年9月3日 16:53
- 已标记为答案 Dummy yoyoModerator 2011年9月9日 2:39
全部回复
-
请仔细看我下划线加粗的部分!
string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JoblD not in (select distinct Table2.JobName from Table3 inner join Table2 on Table3.JobName = Table2.JobName)";
你怎么可以把jobId和JobName相比较呢?
建议把第二个下划线部分改成:
Table2.JobId
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 Dummy yoyoModerator 2011年9月9日 2:39
-
因为JoblD类型为int,JobName类型为nvarchar
- string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JoblD not in (select distinct Table2.JobID from Table3 inner join Table2 on Table3.JobName = Table2.JobName)";
- string str = "select JobName from Table2 where JoblD=" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim()+ "and JobName not in (select distinct Table2.JobName from Table3 inner join Table2 on Table3.JobName = Table2.JobName)";
看需求,请自取一个
另外,好像没看到有Delete语句(似乎不太符合题意?)
Shadowと愉快なコード達
- 已编辑 Shadow .Net 2011年9月3日 16:53
- 已标记为答案 Dummy yoyoModerator 2011年9月9日 2:39