|
Hi,
I want to create a library for all the sql database operations.All other functions are working, but function for returning sqldatareader doesn't work.When I call this function from my page and try to access returned datareader object >it gives the error reader is closed. What to do???
|
|
|
|
|
No one can help you until you show us the code for returning sqldatareader. However, from the error code I suspect that the connection used by the reader is closed.
|
|
|
|
|
This is thecode in my class
sqlDatareader ExecuteReader(string pStrQuery)
{
sqlDatareader dr;
sqlCommand cmdObj=new sqlCommand(pStrQuery);
try
{
cmdObj.open();
dr=cmdObj.ExecuteReader;
return dr;
}
finally
{
cmdObj.close();
}
}
and this is how I use it:
sqlDataReader dr=obj.ExecuteReader(query);
and here it shows datareader is closed if try to read it.I even tried it without finally block.Not working.I'd appreciate any hep.
|
|
|
|
|
Your problem is that you closed the Reader in the Finally block. Whenever execution leaves the Try block FOR ANY REASON, the code in the Finally block is executed, where you close the Reader.
Remove the code from the Try block and run it again. Your Try block is catching any and all errors and supressing them since you don't have a Catch block reporting the error.
|
|
|
|
|
As you you are using try finally block, the connection is closed so it is impossible to read from the reader as SqlDataReader requires open connection. So just return the reader without closing the connection.
|
|
|
|
|
As the others have commented, you need to remove the close on the connection to return it. You should also ensure that the DataReader closes the connection for you. One method of doing this is to pass in CommandBehavior.CloseConnection as a parameter to ExecuteReader .
|
|
|
|
|
Hey Pete,
Thanks for your post. Never realized that the CommandBehavior.CloseConnection enum existed. Very nice tip.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
HI,
Can any one guide me how to run commands from a .Net Application developed in C# at Command prompt(i.E C:\>)
Any links on it would also be helpful
|
|
|
|
|
Hi,
try Process.Start("cmd.exe", args)
If that does not do what you want, have a look at ProcessStartInfo class and use Process.Start(psi)
|
|
|
|
|
|
I know d@nish was trying to get the same point across...
Blog link to be reinstated at a later date.
|
|
|
|
|
I have a DataGridView bound to a table in Sql Server CE. I'd like to filter results but I couldn't figure it out so far. I'm trying to use DataView RowFilter but I couldn't manage it to work. Could you please tell me what should I look for? Here's the code, auto-generated by VS.NET, to bind data:
this.gridRecords.DataSource = this.RecordsBindingSource;
this.RecordsBindingSource.DataMember = "Records";
this.RecordsBindingSource.DataSource = this.tempRecordsDataSetBindingSource;
this.tempRecordsDataSetBindingSource.DataSource = this.tempRecordsDataSet;
this.tempRecordsDataSetBindingSource.Position = 0;
this.tempRecordsDataSet.DataSetName = "TempRecordsDataSet";
this.tempRecordsDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
this.RecordsTableAdapter.ClearBeforeFill = true;
this.RecordsTableAdapter.Fill(this.tempRecordsDataSet.Records);
This is what I tried:
this.tempRecordsDataSet.Records.DefaultView.RowFilter = "Field = 1234567891";
|
|
|
|
|
Your idea of using DataView is correct. However when using view, don't bind the control to the original data table, bind it to the view.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hi all,
Can any one guide me?
how to create crystal report using generic list ? (I am using .NET crystal report)
I have a list of class and using this list I want to create crystal report.
I want to create parameter fields of crystal report at runtime.
|
|
|
|
|
How can i know whether a report is printed that was displayed in the viewer?
Print event occurs when user clicks print button.
Printing can be canceled. so how do we know exactly whether the report was printed or not?
Kanchana
|
|
|
|
|
System.Printing namespace contains PrintServer , PrintQueue and PrintSystemJobInfo classes. Use those classes to find the correct job and then the job has several status properties including IsCompleted .
However, I'm a little bit suspicous about that property since if the actual printer has spooled the data I think it's removed from the queue and the job is marked as complete. However the printer may still be unable to print the job (running out of paper, power loss in the middle of printing etc.).
Mika
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
|
Hi All,
While learning unmanaged code i got few questions Please if anyone knows please let me know.
1. If i have unmanaged code like C or C++ in my C# application then who is going to compile this code ?
2. Can we have intermediate Language (MSIL) for unsafe code?
3. What compiler will do when we make true for "Allow unsafe code" setting in build option of configuration.
4. Which languages comes under unmanaged code ?
I gone through many articles on Web but couldn't got answer for these questions
modified on Tuesday, November 4, 2008 1:43 AM
|
|
|
|
|
Member 4554649 wrote: 1. If i have unmanaged code like C or C++ in my C# application then who is going to compile this code ?
You cannot have mixed languages in the same project. So, yes, you can have a C# project and a C++ project in the same solution. Seperate compilers would have to compile each project, depending on the language used in that project.
Member 4554649 wrote: 2. Can we have intermediate Language (MSIL) for unsafe code?
The question doesn't make sense. All managed code (C#, VB.NET, C++ CLI, ...) is compiled to MSIL, so yes, in all cases, you have MSIL code in unsafe code blocks. But, I don't think that's what you're asking.
Member 4554649 wrote: 3. What compiler will do when we make true for "Allow unsafe code" setting in build option of configuration.
This makes me wonder if you know what "unsafe" code is. An unsafe code block is just a block of code that uses pointers. Since pointer math and types cannot be verified safe at runtime, it's called unsafe code. The Unsafe keyword just tells the compiler that this section of code cannot be verified type safe, so it needs to relax it rules a bit in this section in order to successfully compile the code.
|
|
|
|
|
Thanks Dave,
Actually i got confused in Unmanaged and unsafe code.
Now things are clear in my mind but one thing that needs to be addressed
Unmanaged code means All languages like C,C++,Win API, VC++,VB 6
i.e languages which produces Native code when compiled for windows OS
Is it right ?
One more thing if in my application i have unmanaged code who is going to compile that code ?
|
|
|
|
|
Member 4554649 wrote: Unmanaged code means All languages like C,C++,Win API, VC++,VB 6
Yes, but...there are managed variants of c++ (called c++\cli). The Win API is a framework not a language. It is an unmanaged framework, but it can be called from either managed or unmanaged code. VB6 actually has the option to be compiled as unmanaged or managed code (called P-code in the case of VB6). It's int the project settings somewhere IIRC.
Unmanaged is anything that is compiled straight to machine code and runs directly on the system. Managed means it is compiled to an intermediate language (MSIL for c#, bytecode for Java, etc), and a runtime (like the CLR or JVM) is used to interpret that intermediate language and convert it to machine code as the program is running - This is called JIT compilation (Just In Time).
Member 4554649 wrote: One more thing if in my application i have unmanaged code who is going to compile that code ?
The compiler. GCC for c++ or the visual studio IDE for vc++. You can't mix managed and unmanaged code in the same project.
Simon
|
|
|
|
|
Hi all,
I have created an Excel 2003 AddIn project and created one Setup project also for install the AddIns in target machines. My setup contains the primary out put of the AddIn project. I just came to know some registery entries are required for successful installation. Can any one help me in creating setup project with necessary registery entries.
|
|
|
|
|
Stop cross posting.
Pick 1 forum most related to your question, and ask your question there, and only there. People won't help you any faster if you just post everywhere.
Post 1[^]
Post 2[^]
Post 3[^]
Post 4[^]
Simon
|
|
|
|
|
Hi,
In VS 2005 I am using Reflection to parse .Net System libraries. Using GetMembers(BindingFlags) returns some additional methods other what is defined in the interface/class in .Net system library. For filtering out I am using following BindingFlags combination
BindingFlags::Public | BindingFlags::Instance | BindingFlags::Static | BindingFlags::DeclaredOnly
I am trying to get the declared members in class/interface say for example System.Collection.ICollection which has following 4 members:
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get; }
void CopyTo(Array array, int index);
However using GetMembers I get following 7 members:
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get; }
void CopyTo(Array array, int index);
int get_Count();
bool get_IsSynchronized();
object get_SyncRoot()
I get extra 3 get methods corresponding to each property. How do I suppress or filter out these additional members?
~Manish
|
|
|
|
|
A property is just a declaration which specifies the get and set methods.
Either use GetMethods or take a look at the MemberInfo, theres a whole bunch of info exposed there that you can use for filtering.
|
|
|
|