佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

12
返回列表 发新帖
楼主: johe07

Johe07的VS2005~VB.Net问题集 - 不能加入parameter进query (#38楼)

[复制链接]
 楼主| 发表于 3-4-2006 03:46 PM | 显示全部楼层
它在messagebox那里出现了这个error
"Dynamic SQL generation is not supported against multiple base tables."

是我的design有问题了?

以下是它message的detail....
System.InvalidOperationException was unhandled
  Message="Dynamic SQL generation is not supported against multiple base tables."
  Source="System.Data"
  StackTrace:
       at System.Data.Common.DbCommandBuilder.BuildInformation(DataTable schemaTable)
       at System.Data.Common.DbCommandBuilder.BuildCache(Boolean closeConnection, DataRow dataRow, Boolean useColumnsForParameterNames)
       at System.Data.SqlClient.SqlCommandBuilder.GetUpdateCommand()
       at MPLS.frmMPL.frmMPL_Load(Object sender, EventArgs e) in C:\IT X-Files\JK System\Store\MPLS-N\MPLS-N\frmMPL.vb:line 143
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.Show()
       at MPLS.frmLnSele.cmdOK_Click(Object sender, EventArgs e) in C:\IT X-Files\JK System\Store\MPLS-N\MPLS-N\frmSele.vb:line 287
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MPLS.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
回复

使用道具 举报


ADVERTISEMENT

发表于 3-4-2006 04:04 PM | 显示全部楼层
原帖由 johe07 于 3-4-2006 03:46 PM 发表
它在messagebox那里出现了这个error
"Dynamic SQL generation is not supported against multiple base tables."

是我的design有问题了?

以下是它message的detail.. ...


这是从help file里截出来的解释

Automatically generates single-table commands used to reconcile changes made to a DataSet with the associated SQL Server database
回复

使用道具 举报

 楼主| 发表于 3-4-2006 04:35 PM | 显示全部楼层
原帖由 astral 于 3-4-2006 16:04 发表


这是从help file里截出来的解释

Automatically generates single-table commands used to reconcile changes made to a DataSet with the associated SQL Server database

原来它不能support我这样update....

SQL update,不能通过query得出来的data update进去另一个table....
.Net 不能,VB6亦是如此。。。。

[ 本帖最后由 johe07 于 3-4-2006 04:58 PM 编辑 ]
回复

使用道具 举报

发表于 3-4-2006 07:09 PM | 显示全部楼层
原帖由 johe07 于 3-4-2006 04:35 PM 发表

原来它不能support我这样update....

SQL update,不能通过query得出来的data update进去另一个table....
.Net 不能,VB6亦是如此。。。。

不是不可以,只是不是那样做啦。
你从那么多tables选资料出来,又没有告诉它要怎样update,连update去哪里都没告诉它,它又怎么知道要如何update呢?
为何你不在store procedure里直接update 你的cache(temp table)后再直接return data呢?把它从老远搬出来后又把它老远的送回去,好像点麻烦哦。。。
回复

使用道具 举报

 楼主| 发表于 4-4-2006 08:09 AM | 显示全部楼层
原帖由 astral 于 3-4-2006 19:09 发表

不是不可以,只是不是那样做啦。
你从那么多tables选资料出来,又没有告诉它要怎样update,连update去哪里都没告诉它,它又怎么知道要如何update呢?
为何你不在store procedure里直接update 你的cache(temp t ...


是吗?
update cache??没有听说过。。。。
去找找看咯。。。。
回复

使用道具 举报

发表于 4-4-2006 09:02 AM | 显示全部楼层
原帖由 johe07 于 4-4-2006 08:09 AM 发表


是吗?
update cache??没有听说过。。。。
去找找看咯。。。。

哎呀,我说的cache就是你的temp table啦。。。你不是把它当成cache来用吗?
回复

使用道具 举报

Follow Us
发表于 4-4-2006 09:21 AM | 显示全部楼层
你的做法真复杂... 看得我眼花缭乱...
为什么不考虑用简单一点的方法? sql 可以自己写呀.
回复

使用道具 举报

 楼主| 发表于 4-4-2006 10:01 AM | 显示全部楼层
原帖由 goatstudio 于 4-4-2006 09:21 发表
你的做法真复杂... 看得我眼花缭乱...
为什么不考虑用简单一点的方法? sql 可以自己写呀.

我SQL不强。。。不会写那么复杂的。。。
我也知道很乱。。。抱歉。。。

我的编程功力还很浅,所以,做的program都很复杂。。。
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 4-4-2006 10:02 AM | 显示全部楼层
原帖由 astral 于 4-4-2006 09:02 发表

哎呀,我说的cache就是你的temp table啦。。。你不是把它当成cache来用吗?

哦。。。明白了。。。。
回复

使用道具 举报

 楼主| 发表于 14-9-2006 10:48 AM | 显示全部楼层

Export资料进去Excel

各位,我又来了。。。

最近我有在做一个system,就是export SQL资料去Excel
我想问问,有什么方法可以很快

以下,是我的编程码


  1. Dim dsExcelExport As New System.Data.DataSet
  2.         Dim daExcelExport As System.Data.SqlClient.SqlDataAdapter
  3.         Dim Excel As New Excel.Application
  4.         Dim intColumn, intRow, intColumnValue As Integer
  5.         Dim strExcelFile As String
  6.         Dim strFileName As String
  7.         Dim conCurrent As New SqlClient.SqlConnection

  8.         conCurrent.ConnectionString = "User ID=" & Lid & " ;Password =" & Lpwd & " ;Persist Security Info=False;Initial Catalog=(table_name) ;Data Source=(sql-svr)"
  9.         'conCurrent.ConnectionString = "data source=;initial catalog=pubs;User ID=sa;Password="
  10.         daExcelExport = New System.Data.SqlClient.SqlDataAdapter(strSql, conCurrent)
  11.         daExcelExport.Fill(dsExcelExport)
  12.         Dim strAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly.Location.LastIndexOf("") + 1)
  13.         With Excel
  14.             .SheetsInNewWorkbook = 1
  15.             .Workbooks.Add()
  16.             .Worksheets(1).Select()
  17.             'For displaying the column name in the the excel file.
  18.             For intColumn = 0 To dsExcelExport.Tables(0).Columns.Count - 1
  19.                 .Cells(1, intColumn + 1).Value = dsExcelExport.Tables(0).Columns(intColumn).ColumnName.ToString
  20.             Next
  21.             'For displaying the column value row-by-row in the the excel file.
  22.             For intRow = 0 To dsExcelExport.Tables(0).Rows.Count - 1
  23.                 For intColumnValue = 0 To dsExcelExport.Tables(0).Columns.Count - 1
  24.                     .Cells(intRow + 1, intColumnValue + 1).Value = dsExcelExport.Tables(0).Rows(intRow).ItemArray(intColumnValue).ToString
  25.                 Next
  26.             Next
  27.             'strFileName = InputBox("Please enter the file name.", "Swapnil")
  28.             strExcelFile = strAppPath & "MRPExport" + Date.Today.Date.ToString
  29.             .ActiveWorkbook().SaveAs(strExcelFile)
  30.             .ActiveWorkbook.Close()
  31.         End With
  32.         MessageBox.Show("File exported sucessfully.", "Exporting done", MessageBoxButtons.OK, MessageBoxIcon.Information)
  33. NormalExit:
  34.         Excel.Quit()
  35.         Excel = Nothing
  36.         GC.Collect()
  37.         Exit Function
复制代码


我要输出的资料大概有1万多个,以这个方法,我export需要很久
但是,如果我通过crystal report的export function, 在3分钟之内就export好了

我只是想问问,这个编程码是否可有改进的地方,加快速度?

[ 本帖最后由 johe07 于 14-9-2006 11:10 AM 编辑 ]
回复

使用道具 举报

发表于 14-9-2006 11:06 AM | 显示全部楼层
原帖由 johe07 于 14-9-2006 10:48 AM 发表
各位,我又来了。。。

最近我有在做一个system,就是export SQL资料去Excel
我想问问,有什么方法可以很快

以下,是我的编程码


Dim dsExcelExport As New System.Data.DataSet
        Dim daExcel ...


如何在EXCEL里的sheet加入10多万个record?有什么方法。。我尝试过。EXCEL最多一个sheet可以到65536 ROW而已

[ 本帖最后由 max5007 于 14-9-2006 11:08 AM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 14-9-2006 11:10 AM | 显示全部楼层

回复 #31 max5007 的帖子

打错了。。。。已经改了。。。pai se....
回复

使用道具 举报

发表于 14-9-2006 07:23 PM | 显示全部楼层
cell没用到formula的话,用stream writer write去.csv 好了。。,包你三秒内搞定。。
回复

使用道具 举报

发表于 14-9-2006 09:13 PM | 显示全部楼层
johe07 分批记录进不同的 excel 再加多线程,过后再结合 excel 档,估计会快很多很多。

另一个超好的方法(小章鱼之前用的)就是:把资料储存为 XML spreadsheet 格式,以 .xls 为扩延名,
excel 就可以打开了。
由于是纯文本,速度很快,也很方便多线程分批然后 merge
不过不知道 excel 2003 前的版本可不可以打开。
回复

使用道具 举报

 楼主| 发表于 15-9-2006 12:11 AM | 显示全部楼层
我要输出这些资料去spreadsheet是因为将会拿这些资料作计算。

所以,我不能输出成任何cvs,text等之类的
回复

使用道具 举报

发表于 15-9-2006 12:16 AM | 显示全部楼层
你输出。csv后,在把它save as .xls 咯。。

我也是每天用excel做data analysis 的。对我来说要是纯value的话
.csv 或.xls都没什么差别的。。

[ 本帖最后由 tensaix2j 于 15-9-2006 12:23 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 15-9-2006 12:38 AM | 显示全部楼层
have a try


  1. Sub ExportDataTableToCSV(ByRef dt As DataTable, ByVal strFilename As String)

  2.         Dim i, j As Integer
  3.         Try
  4.             Dim sw As New System.IO.StreamWriter(strFilename)

  5.             'header
  6.             For i = 0 To dt.Columns.Count - 1
  7.                 sw.Write(dt.Columns(i).ColumnName.ToString + " ,")
  8.             Next i
  9.             sw.Write(vbNewLine)

  10.             'data body
  11.             For i = 0 To dt.Rows.Count - 1
  12.                 For j = 0 To dt.Columns.Count - 1
  13.                     sw.Write(dt.Rows(i)(j).ToString() + ",")
  14.                 Next j
  15.                 sw.Write(vbNewLine)
  16.             Next i

  17.             sw.Close()
  18.         Catch ex As Exception
  19.             Throw ex
  20.         End Try

  21.     End Sub
复制代码

[ 本帖最后由 tensaix2j 于 15-9-2006 12:44 AM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 15-9-2006 09:42 AM | 显示全部楼层
谢谢tensaix2j 的回复,这个我会在试试。
-------------------------------------------

现在我有一个棘手的问题,我不明白为什么做不到。

我在form里面,直接从dataset里把一个datatable拉进去form里做成了datagrid.
由于我要filter out data, 然后show 在grid里面,所以我做了以下的动作:

1. 在我的dataset designer里,右击我的datatable1,然后选"Add Query"
2. 我点击了"Query Builder"
3. 我在"Query Builder" 里面,在SQL Command栏目里,我加了" WHERE ID = @Param1", 可是他说我这个query有问题。

我想请问,为什么我加不到Parameter进去我的query里面?我有什么地方做错了?
这是他出现的错误讯息
Error in WHERE clause near '@'.
Unable to parse query text.


这个是成立的,因为我照着tutorial做,为什么tutorial可以成功,我的却不可以?

[ 本帖最后由 johe07 于 15-9-2006 09:44 AM 编辑 ]
回复

使用道具 举报

发表于 15-9-2006 10:11 PM | 显示全部楼层
johe07 XML spreadsheet 如果把扩延名 .xml 换成 .xls
Microsoft Excel 是可以当成 excel 档来打开的(当然 tag 不能有错误)
也可以有 Formula

以下是一个简单的例子,试试抄进 Notepad 然后储存(扩延名记得换成 .xls)然后用 Microsoft Excel 打开

  1. <?xml version="1.0"?>
  2. <?mso-application progid="Excel.Sheet"?>
  3. <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  4. xmlns:o="urn:schemas-microsoft-com:office:office"
  5. xmlns:x="urn:schemas-microsoft-com:office:excel"
  6. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  7. xmlns:html="http://www.w3.org/TR/REC-html40">

  8. <Worksheet ss:Name="Sheet1">
  9. <Table>
  10. <Row><Cell><Data  ss:Type="Number">1</Data></Cell><Cell><Data ss:Type="String">a</Data></Cell></Row>
  11. <Row><Cell><Data ss:Type="Number">2</Data></Cell><Cell><Data ss:Type="String">b</Data></Cell></Row>
  12. <Row><Cell><Data ss:Type="Number">3</Data></Cell><Cell><Data ss:Type="String">c</Data></Cell></Row>
  13. <Row><Cell><Data ss:Type="Number">4</Data></Cell><Cell><Data ss:Type="String">d</Data></Cell></Row>
  14. <Row><Cell><Data ss:Type="Number">5</Data></Cell><Cell><Data ss:Type="String">e</Data></Cell></Row>
  15. <Row><Cell><Data ss:Type="Number">6</Data></Cell><Cell><Data ss:Type="String">f</Data></Cell></Row>
  16. </Table>
  17. </Worksheet>
  18. </Workbook>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-9-2024 07:23 PM , Processed in 0.116902 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表