|
You should only need one IDbConnection instance to one database, and you can just reuse it every time (just open and close it).
I am not sure what you mean by indirect query; however I think its good practice to use the interfaces rather than the specific providers as much as possible, as your provider might change. (i.e. IDbCommand cmd = new OldDbCommand("S... ).
As for the queries, I keep mine as strings, not as string literals, and have them in a config file. That way I don't need to recompile every time i change a query. It also makes it easy to add on constraints on the query ( cmd.CommandText = selectString + "WHERE Cust = " + custId.ToString() ).
|
|
|
|
|
FYI,
Problem #1
Where are you connecting from? Are you connecting from a web service? Windows Form? Asp.net?
Problem #2
Problem #3
Read on on the .NET Documentation. Specifically with the SqlCommandBuilder.. It will automatically generate the SQL queries you require.. Its not as fast, to my understanding, as your own
- danny
|
|
|
|
|
Hi,
I have been building my gui's by hand in my most recent project, and have consistently ran into trouble when trying to size controls. I mimic the form designer code with an InitComponent() method that is run from the constructor, where i create all my controls. In this method, when i try sizing the controls through controls such as:
textBox.Size = new Size(100,30);
or:
textBox.Width = 100;
textBox.Height = 30;
the controls will not be sized. Any thoughts on why they are not sizing properly, or is there another way to do it?
Thanks,
Nikolaj Baer
|
|
|
|
|
Hi,
thanks for the advice. Actaully ResizeRedraw is a protected property, something i can't apply to an instance. However, i kept searching, and found that SuspendLayout() and ResumeLayout() is the proper way to do it.
|
|
|
|
|
Hello,
I am building an application that requires data to be entered into a control that looks like the Data Grid. Basically, it should mimic the functionality of entering data into MS Excel. I know the Data Grid is primarily used to display data binded to a data source, such as a DataSet. Is there any way to display a blank data grid and use it for data entry? If not, what do you experts suggest that I do to get the results I'm looking for?
One possible solution that I came up with was to bind the data grid to the table that the data is destined for. Next, I would add one row of text boxes that would represent each column below the grid. The user could then add the record to the data grid (and underlying table) by typing the details into the the textboxes below the grid, followed by clicking the "Add" button. However, a grid will not appear unless there is data in the underlying table to be displayed. The empty data grid control does not look attractive on a form.
I remember building an application in vb 6.0 where I got around this by placing textboxes over the cells of the data grid control. However, I can't remember exactly how I did this, or if it would even work with the .NET data grid control.
Any help would be greatly appreciated
|
|
|
|
|
you can edit on the datagrid directly (datagrid.readonly = false) without using textboxes in the end of it. If you are writing a windows forms app an empty datagrid is ok, in asp.net things are a bit difficult and i think the idea you said with the textboxes is the best.
to be more easy and more attractive your datagrid study
System.windows.datagridtablestyle and System.windows.datagridtextboxcolumn,
To validate them you can use datatable events rowchanged... or use standard techniques Causesvalidation ....
Good luck, to make a datagrid work perfect needs lot of work
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
Hi,
Is it some one out there who could please help me transelate this C# code to VB.NET?
int vPos=(index <= selectedBand) ? buttonHeight*index : buttonHeight*index+selectedBandHeight;
int height=selectedBand==index ? selectedBandHeight+buttonHeight : buttonHeight;
Thanks,
Richard
|
|
|
|
|
<br />
dim vPos as interger<br />
vPos = buttonHeight * index<br />
if index <= selectedBand then<br />
vPos = vPos + selectedBandHeight<br />
end if<br />
<br />
dim height as interger<br />
height = buttonHeight<br />
if selectedBand=index then<br />
height = height + selectedBandHeight<br />
end if<br />
Something like that?
|
|
|
|
|
So in OnStop I create and start a thread with new Thread(new ThreadStart(funk)) , right?
Thread is doing something and then Stop command comes along and naturaly I get OnStop called. Everything is OK so far. I post to my thread a message somehow for it to quit and OnStop returns right away. SCM thinks that everything was ok. But my worker thread has some work to finish before quitting and it may take time. So it continues until it's done BUT magically the service process disappears in about 20 sec after OnStop returned cutting the execution of my thread right in the middle (or so it seems) of a routine.
How do I avoid that? I want that thread to finish normaly.
|
|
|
|
|
You are suggesting to have actual worker code in the main thread of a service? Then how would I responds to OnStart and continue at the same time with out a separate thread? I'm new to this - please advise! Also wouldn't SCM complain about being unable to stop service in "timely fashion" if that main thread works however long it needs?
I want sevrice to report back to SCM I'm done (kindof) but executable would stay until it finishes what it needs.
|
|
|
|
|
AAAAAaaaaaaa see! That is not what I need to do. My service onstart begins to do the stuff from database - it doesn't respond to commands. So it lives on it's own (second tread seems natural choice, right?) And it does a very lengthy computations (recognizing images). I can not just interrupt it until it's logiñ permits it.
|
|
|
|
|
Well. That is why second thread is beautiful. I don't have to wait for a lot of stuff before reporting "running". What more interesting is that in C++ (ATL template app let's say) the IS a way to tell SCM - "I'm still shutting down", but not in C# (at least I don't see it anywhere).
I just openned an issue with Microsoft. They said "WOW! You should be proud - you're the first one to report/complain about this". I wish I wasn't really. I'm hoping these is still a way to go around this without .NET SP .
I may go to C++ service, but I really hate to do that. On the other hand it's going to be a quicker way then to reorganize code developed over past 9 years that now I have to call from service.
|
|
|
|
|
Yeah. Me too. Quick and let's you concentrate on your business logic... except it seems they abstracted a little to much there this time and now I have to concentrate on the service again.
|
|
|
|
|
You need to wait in your OnStop function until your service has finished shutting down. You might do this with a ManualResetEvent like this:
ManualResetEvent done = new ManualResetEvent(false);
protected override void OnStop()
{
done.WaitOne();
}
Then in your other routine, running on the other thread, just call done.Set(); when you are all done, just before returning.
Burt Harris
|
|
|
|
|
But I already tried even a message box in onstop method. That should've keep it alive for as long as there is the message box, right? Wrong! The process magicaly dissapears in 20 seconds after stop button was hit in SCM and it seem it doesn't metter what I do. The execution of a function just gets cut off right in the middle of a routine. Looks like SCM uses "terminate process" or something...
|
|
|
|
|
In VB6, we had an application which created a connection through a comm port object, and with a winsock client server control, sent data to a handheld device. I was wondering if anyone knew the replacement object for the comm port object, and if the winsock has a replacement. I noticed in passing that sockets seem to be the new communication object, will a socket replace the functionality of both the winsock and comm port control?
Thanks,
Ryan
|
|
|
|
|
I don't there is an exact 'replacement' control for this (not from MS that is), check out the System.Net.Sockets namespace where you will find a Socket class and all kinds of other good stuff.
-Nick Parker
|
|
|
|
|
If you want to use serial port communication in the .NET world you are in trouble. I have tried to do it and needs very very much work because it's not built in and you have to work with win32 with platform invoke, here is an article from msdn that may help you
http://msdn.microsoft.com/msdnmag/issues/02/10/NETSerialComm/default.aspx
if you find something interesting, any tool maybe, please let me know
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
Is there any way to change the height of these headers? Or the alignment for that matter (without changing the alignment of the whole column via a column style). The problem is that I have a Header Text that is bigger than the width of the column and I would like it to display in two lines within the header. The column is a checkbox column so making it wider would not be a great solution. Thanks in advance.
Cheers,
Mike
|
|
|
|
|
i have tried lot of things including this:
char a = (char)13;<br />
char b = (char)10;<br />
<br />
string c;<br />
c=a.ToString()+b.ToString();<br />
<br />
System.Data.DataTable maintable = new DataTable("table1");<br />
maintable.Columns.Add("col1",System.Type.GetType("System.String"));<br />
System.Data.DataRow nr = maintable.NewRow();<br />
nr["col1"]="cdcscsdcds";<br />
<br />
maintable.Rows.Add(nr);<br />
<br />
System.Windows.Forms.DataGridTableStyle ms = new DataGridTableStyle();<br />
ms.MappingName="table1";<br />
System.Windows.Forms.DataGridTextBoxColumn ns = new System.Windows.Forms.DataGridTextBoxColumn();<br />
ns.MappingName="col1";<br />
ns.TextBox.Multiline=true;<br />
ns.HeaderText="dadasdasdasd"+c+"dsadsadsad";<br />
<br />
ms.GridColumnStyles.Add(ns);<br />
<br />
this.maingrid.TableStyles.Add(ms);<br />
this.maingrid.DataSource=maintable;
and nothing works, the only thing to do i think is to build a class that inherits from System.windows.forms.datagridtextboxcolumn and override Paint method which i think is very difficult and the most important needs lot of time
From Greece:
Dimitris Iliopoulos
dimilio@yahoo.com
|
|
|
|
|
I have actually already made my own textboxcolumn class to do some other functionality but I am not sure if the header is part of the column style or part of the grid (or maybe even the table style). I know that I will not be able to use the "Multiline" property as I have combo boxes in the grid and I would like them to stay the same size and always fill the entire cell. Thanks for your help and I would appreciate anyone else's insight into this problem.
Cheers
Mike
|
|
|
|
|
Hello,
I was just wondering if anyone else was getting this type of error.
Basically, in the last little while I have created my own versions of two common Windows controls and I would like to put them all in one project. My first control was a masked text box and everything work fine except that I would lose certain properties that I set in design after I compiled. For example, I had a "Mask Type" enum property that could be set at design time but when I ran the program and I went back to Visual Studio (while the program was still running) the "Masked Type" property would reset to its default state. The program ran properly the first time with the masked type but as soon as I closed it and ran it again, it would use the default value that it had been reset to. This problem frusterated me to no end as I couldn't do anything to save that property but I did narrow it down to that fact that it was because the property was an enum type. As a result, I found that if I moved that enum type to a different class, it would save properly and I could finally move on (although not as happily as I would have hoped). Recently, I have created a customized tab control that would allow me to change the style and colours of the pages. Again everything seemed to work fine but as I neared completion, I noticed that the design view was again not saving the changes that I was making in it after I had compiled. This time is was the pages collection that was losing its settings. Again, if I moved the collection outside of the class and into it's own class, the design time properties saved properly and I could use it normally.
My question is: Does anyone know what I am doing wrong (or possibly doing wrong) Has anyone had this problem with the designer and if so, how did you fix it. I would appreciate any and all help that I could get in this matter. Thanks in advance.
Cheers,
Mike
|
|
|
|
|
Does anyone know if it is possible, using C# and the .NET framework, to get access to the structure of databases in SQL Server? When I say "structure" I mean for example, a programmatic way to get the name of all the tables and their fields and relations, when you know nothing about the database except a connection string for it.
Mark Sanders
|
|
|
|
|
Search MSDN for "sysobjects". It's a "table" where this kind of metadata information is available and it's fully documented on MSDN.
As a sample, if you want the list of all the tables on the current database, run:
select name from sysobjects where xtype = 'U'
ORACLE One Real A$#h%le Called Lary Ellison
|
|
|
|
|
The system tables are subject to change in future versions of SQL server. (They have changed before)
The recomended approach is to use the INFORMATION_SCHEMA views and some system stored procedures, since MS have committed to keep the output of these compatible through all versions on SQL Server they exist on, and they will exist on all future releases of SQL Server. (Meaning MS has added some, but not removed any of them...)
Usage example:
SELECT * FROM INFORMATION_SCHEMA.TABLES
Lookup in BOL's index on INFORMATION_SCHEMA
|
|
|
|