阅读:1353回复:1
关于SHAPE文件和SQL SERVER 数据库连接问题,急!!
<P><STRONG><FONT face=Tahoma size=2> Dim pCom As New System.Data.SqlClient.Command<BR> Dim cnn as new system.data.sqlclient.sqlconnection</FONT></STRONG></P>
<P><STRONG><FONT face=Tahoma size=2> Dim pTable As New MapObjects2.Table<BR> Dim yl As New MapObjects2.MapLayer<BR> Dim dc As New MapObjects2.DataConnection<BR> pcom.Connection = cnn<BR> cnn.Open()<BR> pcom.CommandType = CommandType.Text<BR> yl.GeoDataset = dc.FindGeoDataset("station")<BR> Dim sql As String<BR> sql = "select * from test "<BR> pcom.CommandText = sql<BR> <FONT color=#f70938> pTable.Command = pcom</FONT><BR><BR> If yl.AddRelate("BH", pTable, "BH", True) Then<BR> MsgBox("图层和属性关联成功")<BR> Else<BR> MsgBox("图层和属性关联不成功,不能模拟")<BR> End If<BR> cnn.Close()<BR><FONT color=#bb4444>未处理的“System.InvalidCastException”类型的异常出现在 mscorlib.dll 中。<BR><BR>其他信息: 不支持此接口 错误出现在 pTable.Command = pcom<BR>,请各位指点</FONT></FONT></STRONG></P> <P><STRONG><FONT face=Tahoma color=#000000 size=2>---------------------------------------------------------</FONT></STRONG></P> <P><STRONG><FONT face=Tahoma size=2>又用下面的代码,还是不能建立联结</FONT></STRONG></P> <P>Dim dc As New MapObjects2.DataConnection</P> <P><STRONG><FONT face=Tahoma size=2>Dim pTable As New MapObjects2.Table<BR> Dim yl As New MapObjects2.MapLayer<BR> Dim cnn as new system.data.sqlclient.sqlconnection</FONT></STRONG></P> <P><STRONG><FONT face=Tahoma size=2> yl.GeoDataset = dc.FindGeoDataset("station")<BR> pTable.Server = "10.49.2.111"<BR> pTable.Database = "instance=rain"<BR> pTable.User = "zdzyl"<BR> pTable.Password = "zdzylserver"<BR> pTable.Name = "test"</FONT></STRONG></P> <P><STRONG><FONT face=Tahoma size=2> If ly.AddRelate("BH", pTable, "BH", True) Then<BR> '<BR> MsgBox("图层和属性关联成功")<BR> 'MobjectRender(ly)<BR> Else<BR> MsgBox("图层和属性关联不成功,不能模拟")<BR> End If</FONT></STRONG></P> <P> <FONT color=#bb4444>运行结果也是"<STRONG><FONT face=Tahoma size=2>图层和属性关联不成功,不能模拟"</FONT></STRONG></FONT></P> <P><STRONG><FONT face=Tahoma color=#bb4444 size=2>为什么建立不了关联呢?请高手指教!</FONT></STRONG><BR></P> |
|
1楼#
发布于:2009-03-22 16:13
<P>请高手指点呀!!!自己顶一下</P>
|
|