VB.Net Datagridview数据源v / s SQL查询问题 [英] VB.Net Datagridview Datasource v/s SQL Query Problem
问题描述
尊敬的先生,
我正在使用
datagridview.datasource = datatable.copy
来填充没有链接数据源的数据。
在这种情况下,为什么我无法编辑单元格?
1)查询下面不要更改VB.Net Datagridview单元格内容:
strSQL =& quot;选择Row_Number()Over(Order By A.Id)作为SN, A.Id,A.Face As [Object Name],B.Visi,B.AddNew,B.Edit,B.Del,B.Prnt,B.Reg,B。 XL,B.Txt,B.Email来自MSG_URightMaster A& quot; strSQL = strSQL& amp; & quot; Left Join MSG_URight B On A.Id = B.RightId Where B.UserId ='& quot; &放大器;放大器; flxGroup(flxGroup.Row,1)& amp; &安培; QUOT;&安培;#39; & quot;
2)我还使用了以下查询,这是完美的我可以更改任何单元格内容:
DIM strSQL作为字符串在查询下面让我们更改VB.Net Datagridview单元格内容:strSQL =& quot ;选择Row_Number()Over(Order By A.Id)As SN,A.Id,A.Face As [Object Name],& quot; strSQL = strSQL& amp; & quot;(选择B.Visi来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')作为Visi,& quot; strSQL = strSQL& amp; & quot;(选择B.AddNew来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')As AddNew,& quot; strSQL = strSQL& amp; & quot;(选择B.Edit来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')如编辑,& quot; strSQL = strSQL& amp; & quot;(选择B.Del来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')As Del,& quot; strSQL = strSQL& amp; & quot;(从MSG_URight B中选择B.Prnt,其中A.Id = B.RightId和B.UserId ='& quot;& amp; a
mp; flxGroup (flxGroup.Row,1)& amp;& quot;')As Prnt,& quot; strSQL = strSQL& amp; & quot;(选择B.Reg来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')作为Reg,& quot; strSQL = strSQL& amp; & quot;(选择B.XL来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')作为XL,& quot; strSQL = strSQL& amp; & quot;(选择B.Txt来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')作为Txt,& quot; strSQL = strSQL& amp; & quot;(选择B.Email来自MSG_URight B,其中A.Id = B.RightId和B.UserId ='& quot;& amp; flxGroup(flxGroup.Row,1)& amp; & quot;')As Email& quot; strSQL = strSQL& amp; & quot;来自MSG_URightMaster A Order By A.ID& quot;
我很困惑。你能告诉我们为什么吗?
请告诉我,我之间的问题是什么以及我无法解决的问题改变单元格内容。
问候 -
Sanjeeb< / pre>
Respected Sir,
I am using
datagridview.datasource=datatable.copy
to populate data which has no linking datasource at all.
In that case, why am I unable to edit a cell ?
1) Below Query Let Not Change the VB.Net Datagridview Cell Content:
strSQL = "Select Row_Number() Over (Order By A.Id) As SN, A.Id, A.Face As [Object Name],B.Visi,B.AddNew,B.Edit,B.Del,B.Prnt,B.Reg,B. XL,B.Txt,B.Email from MSG_URightMaster A " strSQL = strSQL & "Left Join MSG_URight B On A.Id=B.RightId Where B.UserId='" & flxGroup(flxGroup.Row, 1) & "' "
2) I have also used below query which is perfect and I am able to change any cell content:
DIM strSQL as string Below Query Let Change the VB.Net Datagridview Cell Content: strSQL = "Select Row_Number() Over (Order By A.Id) As SN, A.Id, A.Face As [Object Name], " strSQL = strSQL & "(Select B.Visi From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As Visi, " strSQL = strSQL & "(Select B.AddNew From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As AddNew, " strSQL = strSQL & "(Select B.Edit From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As Edit, " strSQL = strSQL & "(Select B.Del From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As Del, " strSQL = strSQL & "(Select B.Prnt From MSG_URight B Where A.Id=B.RightId And B.UserId='" &a
mp; flxGroup(flxGroup.Row, 1) & "') As Prnt, " strSQL = strSQL & "(Select B.Reg From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As Reg, " strSQL = strSQL & "(Select B.XL From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As XL, " strSQL = strSQL & "(Select B.Txt From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As Txt, " strSQL = strSQL & "(Select B.Email From MSG_URight B Where A.Id=B.RightId And B.UserId='" & flxGroup(flxGroup.Row, 1) & "') As Email " strSQL = strSQL & "From MSG_URightMaster A Order By A.ID "
I am so confused. Could you please advise why?
Kindly suggest to me what's the problem between queries that I am not able to change cell content.
Regards-
Sanjeeb</pre>
推荐答案
我的问题是,为了进一步理解你的问题,你将为什么要复制表格。我的经验是绑定到一个新实例。
My question, to further understand your question, would be why are you copying the table. My experience is to just bind to a new instance.
Dim dt as New DataTable
dt = datatable
grid.Datasource = dt
这应允许读/写实例用于操作目的。
That should allow a read/write instance for manipulation purposes.
这篇关于VB.Net Datagridview数据源v / s SQL查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!