|
hi
i found an article in codeproject as DataGridPrinter that print datagrid good. but it has written with VB.Net and i want it in csharp. when i create dll in VB.Net and i use it in c# the following error shown me :
Unable to cast object of type 'System.Windows.Forms.BindingSource' to type 'System.Data.DataTable'
and when i set Datagrid1.DataSource = ds1.Tables["Table1"]; the following error shown me :
//in Line 374
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
how to solve my problem and do you have a other class that print datagrid in C# with header and footer ?
thanks ..
|
|
|
|
|
How to read a exact line from .txt file.
Example:"FileName.txt", line 15.
Vasildb
|
|
|
|
|
File.ReadAllLines will read your file into a string array. Then you can use index 14 to read the 15th line.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I'm starting with C# and the VS2005 and got some trouble with the DataGridView element.
I have designed a simple form with an DataGridView and bound the grid to MS access database file (*.mdb) via the VS2005 Designer.
If I start the application and open the form, the DataGridView will open and filled correctly with the included data inside the database file.
When I edit some rows or add new rows the changes will stored inside the generated Dataset, I believe, because if I close and reopen the form the changes will displayed correctly.
But if I close and restart the application the changes are lost.
So I put a Save button to the form and the devicesTableAdapter.Update(this.aStreamsDataSet.Devices); inside it's handler. But also the information doesn't store to the database.
On further test I saw that if I add a new row to the DataGridView the 'count' will increment inside the DataTable.
If I edit some existing rows the 'rowChanged' is always null inside the DataTable.
Do I have set special properties of the DataGridView? It's only displaying availlable or what else?
Did you know a simple instruction to use this control for editing the data also?
I'm glad for every suggestion.
Thanks a lot
Alex
|
|
|
|
|
Hi,
i guess you have to give the dataset with changes in the update method from the adapter.
you can get them by using getchanges on your current dataset..
also fill in the delete-, insert- updatecommands on the adpater .. its possible using a commandbuilder for it...
hope this helps..
greetz
Kurt
|
|
|
|
|
Hi Kurt,
I had a look to my automatic generated adapter the following and find the following commandstrings/SQL-statements. May you could say if this statements are correct? Will the question mark replace on code execution or are this default/sample entries which doesn't work?
1.) this._adapter.UpdateCommand.CommandText = @"UPDATE `Devices` SET `Name` = ?, `IPAddress` = ?, `Type` = ?, `Subtype` = ?, `Status` = ?, `Comment` = ?, `Activate` = ? WHERE ((`ID` = ?) AND ((? = 1 AND `Name` IS NULL) OR (`Name` = ?)) AND ((? = 1 AND `IPAddress` IS NULL) OR (`IPAddress` = ?)) AND ((? = 1 AND `Type` IS NULL) OR (`Type` = ?)) AND ((? = 1 AND `Subtype` IS NULL) OR (`Subtype` = ?)) AND ((? = 1 AND `Status` IS NULL) OR (`Status` = ?)) AND ((? = 1 AND `Comment` IS NULL) OR (`Comment` = ?)) AND ((? = 1 AND `Activate` IS NULL) OR (`Activate` = ?)))";
2.) this._adapter.InsertCommand.CommandText = "INSERT INTO `Devices` (`Name`, `IPAddress`, `Type`, `Subtype`, `Status`, `Comment" + "`, `Activate`) VALUES (?, ?, ?, ?, ?, ?, ?)";
3.) this._adapter.DeleteCommand.CommandText = @"DELETE FROM `Devices` WHERE ((`ID` = ?) AND ((? = 1 AND `Name` IS NULL) OR (`Name` = ?)) AND ((? = 1 AND `IPAddress` IS NULL) OR (`IPAddress` = ?)) AND ((? = 1 AND `Type` IS NULL) OR (`Type` = ?)) AND ((? = 1 AND `Subtype` IS NULL) OR (`Subtype` = ?)) AND ((? = 1 AND `Status` IS NULL) OR (`Status` = ?)) AND ((? = 1 AND `Comment` IS NULL) OR (`Comment` = ?)) AND ((? = 1 AND `Activate` IS NULL) OR (`Activate` = ?)))";
If I debug my code I saw the this.Adapter.Update(dataTable); methode will called, but it doesn't work.
Next I try to check the getchanges().
Thanks alex
|
|
|
|
|
I'll guess the query will be ok ( but i don't have qoutes around the fieldnames) and yes the question is replaced by the given parameter value.
Maybe better to define your own query and use less fields in the where clause.
try this :
Tmp_datatable = yourdatatable.getchanges();
this.Adapter.Update(Tmp_datatable);
Tmp_datatable only has the modified rows
greetz.
|
|
|
|
|
Hi,
I put the code inside and also debug them, looks like your sample;
try<br />
{<br />
if (this.Validate() == false){<br />
MessageBox.Show("Validation is false verify your input!");<br />
return;<br />
}<br />
this.devicesBindingSource.EndEdit();<br />
VideoStreamsDataSet.DevicesDataTable Tmp_datatable = new VideoStreamsDataSet.DevicesDataTable();<br />
Tmp_datatable = VideoStreamsDataSet.DevicesDataTable)this.videoStreamsDataSet.Devices.GetChanges();<br />
this.devicesTableAdapter.Update(Tmp_datatable);<br />
MessageBox.Show("Update successful");<br />
}<br />
catch (System.Exception ex){<br />
MessageBox.Show("Update failed");<br />
}
If I add a new row the values will update and displayed at the DataGridView. But also if I close the application and restart, I could see the data isn't stored at database.
If I modify a row so I catch an exeption calling me this:
Parallelitätsverletzung : Der UpdateCommand hat sich auf 0 der erwarteten 1 Datensätze ausgewirkt.
means:
parallel violation: The UpdateCommand has got 0 of expected 1 data record affected.
Did you have some idea or maybe some complete smale sample that's works correct. I'm much more than frustrated.
Thanks alex
|
|
|
|
|
concerning the update is suggest not to use the cmdbuilder but do it yourself. it takes a little more time but your sure it's the way you want it..
just do the update using the key fields in the where clause..
Also autonumbering and datetime fields can cause problems in the where clause.
example :
WagonsAdapter.UpdateCommand = new OleDbCommand();
WagonsAdapter.UpdateCommand.Connection = connection;
WagonsAdapter.UpdateCommand.CommandText = "UPDATE Wagons SET Wag_Name = ?, Wag_Tag1 = ?, Wag_Tag2 = ?, Wag_Info = ?, Wag_Date = ?, Wag_Active = ?, Wag_RecordStatus = ? WHERE Wag_ID = ?";
WagonsAdapter.UpdateCommand.Parameters.Add("Name", OleDbType.VarWChar, 0, "Wag_Name");
WagonsAdapter.UpdateCommand.Parameters.Add("Tag1", OleDbType.Integer, 0, "Wag_Tag1");
WagonsAdapter.UpdateCommand.Parameters.Add("Tag2", OleDbType.Integer, 0, "Wag_Tag2");
WagonsAdapter.UpdateCommand.Parameters.Add("Info", OleDbType.VarWChar, 0, "Wag_Info");
WagonsAdapter.UpdateCommand.Parameters.Add("Date", OleDbType.Date, 0, "Wag_Date");
WagonsAdapter.UpdateCommand.Parameters.Add("Active", OleDbType.Boolean, 0, "Wag_Active");
WagonsAdapter.UpdateCommand.Parameters.Add("RecordStatus", OleDbType.Integer, 0, "Wag_RecordStatus");
WagonsAdapter.UpdateCommand.Parameters.Add("ID", OleDbType.Integer, 0, "Wag_ID");
this works fine... i also had the same problem using the cmdbuilder..
greetz.
|
|
|
|
|
Hi Kurt,
sorry stop here. I found the error, it's always the user.
I discovered there more than one databasefile inside my project. And then I detect that the VisualStudio2005 always copy the original file into the /bin/debug diretory on program start. That's the explanation why always the new data was lost after program start.
I disable that feature on my project settings now.
Sorry that I dissipate your time for this little mistake.
So thanks a lot for your support.
greets alex
|
|
|
|
|
Hi All,
My app is crashing with a C++ exception (even though it's c# 2.0)
First-chance exception at 0x7c812a5b in HDCapture.exe: Microsoft C++ exception: EEException at memory location 0x03c7f368..
I cannot find anything about what this exception means in msdn, or even googling for it.
Does anyone have any ideas?
It's thrown when one thread interrupts another thread which is in a Thread.Sleep(Timeout.Infinite). The code pointer is on the Thread.sleep line.
I'm really stuck for how to diagnose this.
Thanks
Jon
|
|
|
|
|
Sounds like you're using a C++ component ( such as DirectX ) and it's what is crashing.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Indeed I am - directshow. But i'm using directshow.net. Also, i've got a reference to a C++/CLI assembly too.
Any pointers on what the exception means?
|
|
|
|
|
OK, if the C++/CLI assembly is your own, put some break points in it. Sorry, I have no idea what the problem is, just that that's the probable cause.
Jon Hulatt wrote: But i'm using directshow.net.
Doesn't matter, that's just a wrapper.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi
how can i protect my dll from giving out the source code. As there are many free tools that can generate whole code.So how is my dll secure.
I donot want to obfuscate the code to look unreadle but i want it not to be opened at all. It seems it can be done by removing the CLI header. How can i do that if possible.
regards.
|
|
|
|
|
|
hi
I have wriiten my own obfuscator but that can be open back also. So i want something so that our dll is secured to open in any tools.
thanks.
|
|
|
|
|
Hi,
I need to manipulate the 'SortedArray' class in .net so that it allows the entry of the same key more than once. At the same time, it should have all the other properties and methods as it had before. This is crucial to my project.
I am totally unfamiliar with overriding the base classes to produce this kind of desired functionality.
Could you spare some of your precious time to help me out with the problem ?
-Sreerag
|
|
|
|
|
I suspect you'd do better to take another container class, and either make it sorted, or simply sort it every time you add an item. I suspect that the requirement of items being unique is an assumption that could cause you grief in a lot of places within the class.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi all,
I have this bug where my main Form is getting set to WS_DISABLED somtimes and I don't know how it is happening since I am never explicitly doing this in my code (or at least not that I am aware of).
To make matters worse the Window Style event is never called for WS_DISABLED!
Does anyone have an idea how I can track what (object or other) is setting WS_DISABLED on my main Form?
It seems to be happening sometimes after I open and close a MessageBox, but the behavior is completely random. Sometimes the form locks up and sometimes it does not. Using Winspector I am able to change the window style to "re-enable" it and I am keeps running fine again.
Kind thanks,
Serge
|
|
|
|
|
How can i get the names of the tables in a database using System.Data.Odbc
sAqIb
|
|
|
|
|
select * from INFORMATION_SCHEMA.TABLES
|
|
|
|
|
can i use the same query to get the tables from a specific database e.g. from northwind
sAqIb
|
|
|
|
|
try
use northwind<br />
select * from INFORMATION_SCHEMA.TABLES
|
|
|
|
|
i tried above query, its working fine for sql server. But i also want to get the list of tables from other databases like oracle, mysql, ms access.
isn't there any single query which can get the list of all tables from any database?
sAqIb
|
|
|
|