制作数据 [英] making datareaders

查看:63
本文介绍了制作数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队


我很难让这些数据读取器正常工作


我只是想能够集中我的GetDataReader函数;所以我

可以传递一个简单的SQL语句并传回一个有效的DataReader

对象。


我去过整天都在为此而苦恼。我一直在尝试''新'和

不是新的,只是为此而烦恼;我称之为早期..


我很确定我的联系工作正常;我知道我的SQL是

正常工作。

我可以设置一个命令,它工作正常(executeNonQuery)。


我无法弄清楚我在这方面做错了什么。


就像 - 它继续抱怨我已经有了数据集由

同名;难道不应该让这更容易吗?


---------------------------- ---------------------------------


System.Transactions严重: 0:< TraceRecord

xmlns =" http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"

Severity =" Critical"> ;< TraceIdentifier> http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled< / TraceIdentifier>< Description>未处理

异常< /说明>< AppDomain> FileMon.vshost.exe< / AppDomain>< Exception>< ExceptionType> System.NullRef erenceException,

mscorlib,Version = 2.0.0.0,Culture = neutral,

PublicKeyToken = b77a5c561934e089< / ExceptionType>< Message> Object

引用未设置为对象的实例。< / Message>< StackTrace>

在FileMon.basCatalog.Catalog()中的C:\ Documents / settings \ aarkem \ My

Documents\Visual Studio

2005 \Projects\FileMon8_20060501\FileMon_9\basCatal og.vb:第28行

at FileMon.frmMain.Button1_Click(Object发件人,EventArgs e)在

C:\Documents and Settings \aarkem \ My Documents \ Visual Studio 2005 \Projects\FileMon8_20060501 \FileMon_9 \frmMain。 vb:第19行

在System.Windows.Forms.Control.OnClick(EventArgs e)

在System.Windows.Forms.Button.OnClick(EventArgs e)

System.Windows.Forms.Control.WmMouseUp上的
(消息& amp; amp; m,

MouseButtons按钮,Int32点击)

在System.Windows.Forms.Control.WndProc(消息& amp; a mp; m)

在系统.Windows.Forms.ButtonBase.WndProc(Message& am p; amp; m)

at System.Windows.Forms.Button.WndProc(Message& amp; amp; am p; m)

at

System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& amp; amp;

m)

at

System.Windows.Forms.Control.ControlNativeWindow.W ndProc(消息& amp;

m)

在System.Windows.Forms .NativeWindow.DebuggableCallba ck(IntPtr hWnd,

Int32 msg,IntPtr wparam,IntPtr lparam)

at

System.Windows.Forms.UnsafeN ativeMethods.DispatchM essageW(MSG& amp;

msg)



System.Windows.Forms.Application.ComponentManager。 System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32

dwComponentID,Int32 reason,Int32 pvLoopData)

at

System.Windows .Forms.Application.ThreadContext.Run MessageLoopInner(Int32

reason,ApplicationContext context)

at

System.Windows.Forms.Application.ThreadContext .Run MessageLoop(Int32

原因,ApplicationContext上下文)

在System.Windows.Forms.Application.Run(Form mainForm)

在FileMon C中的.frmMain.Main():\ Documents and Settings \ aarkem \我/

Documents \ Visual Studio 2005 \Projects\FileMon8_20060501 \ FileMon_9\frmMain。 Designer.vb:第2行

在System.AppDomain.nExecuteAssembly(程序集,String []

args)

在System.AppDomain。 ExecuteAssembly(String assemblyFile,Evidence

assemblySecurity,String [] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionCon text

executionContext,ContextCallback callback,Object state)

at

System.Threading.ThreadHelper.ThreadStart()< / StackTrace>< ExceptionString> System.NullReferenceEx ception:

对象引用未设置为一个对象的实例。

在FileMon.basCatalog.Catalog()中的C:\Documents和

Settings\aarkem \ My Documents \ Visual Studio

2005 \Projects\FileMon8_20060501\FileMon_9\basCatal og.vb:第28行

在FileMon.f rmMain.Button1_Click(Object sender,EventArgs e)在

C:\Documents and Settings \aarkem \ My Documents \ Visual Studio 2005 \Projects \\ \\FileMon8_20060501\FileMon_9\frmMain。 vb:第19行

在System.Windows.Forms.Control.OnClick(EventArgs e)

在System.Windows.Forms.Button.OnClick(EventArgs e)

System.Windows.Forms.Control.WmMouseUp上的
(消息& amp; amp; m,

MouseButtons按钮,Int32点击)

在System.Windows.Forms.Control.WndProc(消息& amp; a mp; m)

在系统.Windows.Forms.ButtonBase.WndProc(Message& am p; amp; m)

at System.Windows.Forms.Button.WndProc(Message& amp; amp; am p; m)

at

System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& amp; amp;

m)

at

System.Windows.Forms.Control.ControlNativeWindow.W ndProc(消息& amp;

m)

在System.Windows.Forms .NativeWindow.DebuggableCallba ck(IntPtr hWnd,

Int32 msg,IntPtr wparam,IntPtr lparam)

at

System.Windows.Forms.UnsafeN ativeMethods.DispatchM essageW(MSG& amp;

msg)



System.Windows.Forms.Application.ComponentManager。 System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32

dwComponentID,Int32 reason,Int32 pvLoopData)

at

System.Windows .Forms.Application.ThreadContext.Run MessageLoopInner(Int32

reason,ApplicationContext context)

at

System.Windows.Forms.Application.ThreadContext .Run MessageLoop(Int32

原因,ApplicationContext上下文)

在System.Windows.Forms.Application.Run(Form mainForm)

在FileMon C中的.frmMain.Main():\ Documents and Settings \ aarkem \我/

Documents \ Visual Studio 2005 \Projects\FileMon8_20060501 \ FileMon_9\frmMain。 Designer.vb:第2行

在System.AppDomain.nExecuteAssembly(程序集,String []

args)

在System.AppDomain。 ExecuteAssembly(String assemblyFile,Evidence

assemblySecurity,String [] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionCon text

executionContext,ContextCallback callback,Object state)

at

System.Threading.ThreadHelper.ThreadStart()< / ExceptionString>< / Exception>< / TraceRecord>


-------------------------------

公共子目录()


TOTAL_FILEKEEP = 0

ROOTFOLDER_DINCLAUSE = DinClause(ROOTFOLDERID,ROOTFOLDERS,

" ACTIVE = 1")


Dim rootFolderID As Integer

Dim RootFolder As String


Dim DR As New System.Data.SqlClient.SqlDataReader

DR = Nothing

SetDataReader(DR," EXEC spRootFoldersToCatalog")


虽然DR.Read

RootFolder = DR.GetValue(1).ToString

rootFolderID = CInt(DR.GetValue(0) .ToString)

调用RootFolder_Catalog(RootFolder,rootFolderID)

结束时

Files_Catalog()


结束子

--------------------------------------- -----------------------------------------

公开Sub SetDataReader(ByRef thisDR As

System.Data.SqlClient.SqlDataReader,ByVal strSql As String)

frmMain.WriteStatus(strSql)


Dim cmd As New System.Data.SqlClient.SqlCommand


cmd.CommandText = strSql

cmd.Connection = cnnX

尝试

thisDR = cmd.ExecuteReader

Catch ex As Exception

MsgBox(ex.ToString)

结束尝试


结束次级

- ---------------------------------------------

Public Sub RunSql(ByVal strSql As String)


Dim cmd As New System.Data.SqlClient.SqlCommand


frmMain.WriteStatus (strSql)

cmd.CommandText.Equals(strSql)


尝试

cmd.ExecuteNonQuery()

Catch ex As Exception

frmMain.WriteStatus(" SQL FAILED:" &安培; strSql)

停止

结束尝试


结束子

------- --------------------------------------

team

i''m having a tough time getting these data readers to work correctly

I''d just like to be able to centralize my GetDataReader functions; so i
can pass a simple SQL statement and be passed back a valid DataReader
object.

I''ve been slaving with this all day long. I''ve been trying ''new'' and
not new and just slaving over this; im calling it an early day..

I''m pretty darn sure i''ve got my connection working; i know my SQL is
working correctly.
I can setup a command and it works just fine (executeNonQuery).

I just can''t figure out what i''m doing wrong on this side.

It''s like-- it keeps on complaining that i''ve already got a dataset by
the same name; shouldn''t MARS make this easier??

-------------------------------------------------------------

System.Transactions Critical: 0 : <TraceRecord
xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled
exception</Description><AppDomain>FileMon.vshost.exe</AppDomain><Exception><ExceptionType>System.NullRef erenceException,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Object
reference not set to an instance of an object.</Message><StackTrace>
at FileMon.basCatalog.Catalog() in C:\Documents and Settings\aarkem\My
Documents\Visual Studio
2005\Projects\FileMon8_20060501\FileMon_9\basCatal og.vb:line 28
at FileMon.frmMain.Button1_Click(Object sender, EventArgs e) in
C:\Documents and Settings\aarkem\My Documents\Visual Studio
2005\Projects\FileMon8_20060501\FileMon_9\frmMain. vb:line 19
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message&amp ;amp; m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message&amp;a mp; m)
at System.Windows.Forms.ButtonBase.WndProc(Message&am p;amp; m)
at System.Windows.Forms.Button.WndProc(Message&amp;am p; m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message&amp;amp;
m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&amp;amp;
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&amp;amp;
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FileMon.frmMain.Main() in C:\Documents and Settings\aarkem\My
Documents\Visual Studio
2005\Projects\FileMon8_20060501\FileMon_9\frmMain. Designer.vb:line 2
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at
System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>System.NullReferenceEx ception:
Object reference not set to an instance of an object.
at FileMon.basCatalog.Catalog() in C:\Documents and
Settings\aarkem\My Documents\Visual Studio
2005\Projects\FileMon8_20060501\FileMon_9\basCatal og.vb:line 28
at FileMon.frmMain.Button1_Click(Object sender, EventArgs e) in
C:\Documents and Settings\aarkem\My Documents\Visual Studio
2005\Projects\FileMon8_20060501\FileMon_9\frmMain. vb:line 19
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message&amp ;amp; m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message&amp;a mp; m)
at System.Windows.Forms.ButtonBase.WndProc(Message&am p;amp; m)
at System.Windows.Forms.Button.WndProc(Message&amp;am p; m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message&amp;amp;
m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&amp;amp;
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&amp;amp;
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at FileMon.frmMain.Main() in C:\Documents and Settings\aarkem\My
Documents\Visual Studio
2005\Projects\FileMon8_20060501\FileMon_9\frmMain. Designer.vb:line 2
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at
System.Threading.ThreadHelper.ThreadStart()</ExceptionString></Exception></TraceRecord>

-------------------------------
Public Sub Catalog()

TOTAL_FILEKEEP = 0
ROOTFOLDER_DINCLAUSE = DinClause("ROOTFOLDERID", "ROOTFOLDERS",
"ACTIVE=1")

Dim rootFolderID As Integer
Dim RootFolder As String

Dim DR As New System.Data.SqlClient.SqlDataReader
DR = Nothing
SetDataReader(DR, "EXEC spRootFoldersToCatalog")

While DR.Read
RootFolder = DR.GetValue(1).ToString
rootFolderID = CInt(DR.GetValue(0).ToString)
Call RootFolder_Catalog(RootFolder, rootFolderID)
End While
Files_Catalog()

End Sub
--------------------------------------------------------------------------------
Public Sub SetDataReader(ByRef thisDR As
System.Data.SqlClient.SqlDataReader, ByVal strSql As String)
frmMain.WriteStatus(strSql)

Dim cmd As New System.Data.SqlClient.SqlCommand

cmd.CommandText = strSql
cmd.Connection = cnnX
Try
thisDR = cmd.ExecuteReader
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub
-----------------------------------------------
Public Sub RunSql(ByVal strSql As String)

Dim cmd As New System.Data.SqlClient.SqlCommand

frmMain.WriteStatus(strSql)
cmd.CommandText.Equals(strSql)

Try
cmd.ExecuteNonQuery()
Catch ex As Exception
frmMain.WriteStatus("SQL FAILED: " & strSql)
Stop
End Try

End Sub
---------------------------------------------

推荐答案

db*******@hotmail.com 写道:
db*******@hotmail.com wrote:
Dim DR As New System.Data.SqlClient.SqlDataReader
DR = Nothing


首先,你宣布一个一个DataReader的新实例,但是然后在

下一行你抛弃它!这里不需要New关键字

你可以删除DR = Nothing行。

SetDataReader(DR,EXEC spRootFoldersToCatalog)

>虽然DR.Read
Dim DR As New System.Data.SqlClient.SqlDataReader
DR = Nothing
First thing, you declare a new instance of a DataReader but then in
the next line you throw it away! The New keyword is not needed here
and you can delete the DR = Nothing line.
SetDataReader(DR, "EXEC spRootFoldersToCatalog")

While DR.Read




假设您的存储过程正在执行,那么您需要在尝试使用之前检查是否

DR是什么它。我相信这就是问题。

您的存储过程没有返回任何内容。您应该使用SQL

Profiler来帮助确定您没有收到任何数据的原因。



Assuming your stored procedure is executing, then you need to check if
DR is Nothing before you try to use it. I believe that is the problem.
Your stored procedure is not returning anything. You should use SQL
Profiler to help determine why you are not getting any data back.


我收到数据


i将删除新关键字;在编译期间它很窒息说

i需要先用它来做一些事情才能从中获取价值或

这些东西......


我可以吗


Dim DR as System.Data.SqlClient.SqlDataReader = GetDataReader(" EXEC

spRootFoldersToCatalog")


??

i am getting data back

i will delete the new keyword; it was choking during compilation saying
i needed to do something with it before i get values from it or
something along those lines..

can i do

Dim DR as System.Data.SqlClient.SqlDataReader = GetDataReader("EXEC
spRootFoldersToCatalog")

??


你必须编写GetDataReader函数来返回DataReader,

但是,这可能是首选方法。

You''d have to write your GetDataReader function to return a DataReader,
but yes, that is probably the preferred method.


这篇关于制作数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆