|
This, which comes from a diffrent part of the code works
foreach (DataRow dr in TheDataTable.Rows)
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
string data = dr[i].ToString();
data = data.Replace("\"","\"");
sw.Write(data);
}
if (i < iColCount - 1)
{
sw.Write(separator);
}
}
sw.Write(sw.NewLine);
}
the diffrence with the other one is that, I want to put the elements back into a datatable, for other processing.
I how do I make the change of the field values, then move the values into a data table again ?
Let's do this !
|
|
|
|
|
Try using a for loop instead of for each. That should solve your problem
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I changed it to this:
for (int j = 0; j < dtExport.Rows.Count; j++)
{
for (int i = 0; i < dtExport.Columns.Count; i++)
{
if (!Convert.IsDBNull(data = dtExport.Rows[j][i].ToString()))
{
data = dtExport.Rows[j][i].ToString();
data = data.Replace("\"", "\"");
RowZ.Add(data.ToString());
}
}
dtExport.Rows.Add(RowZ.ToArray());
}
but now I get this error System.ArgumentException:input array is longer than the number of columns in the table
Let's do this !
|
|
|
|
|
I don't see any definition for RowZ, does it have more columns than the rows in the dtExport table?
|
|
|
|
|
This is the definition, Arraylist Rowz = new Arraylist () Its an array list
Let's do this !
|
|
|
|
|
Okay, I see. On the second loop you continue to add to the array RowZ, this means that it contains the column values for two rows by the time it gets to the dtExport.Rows.Add method. Since the array has more items in it than columns, the Add method fails as it doesn't know what to do with all that extra data.
At the start of the loop over each row, you need to clear out the array.
RowZ.Clear();
|
|
|
|
|
Do not put your updating statement within the foreach scope. Try use "for(int i=0;i
|
|
|
|
|
Hi,
I have done that, and also placing the Row.Clear before the rows, but I still get the error: input array is longer than the number of columns in this table error ? Where should I have it ?
for (int j = 0; j < dpExport.Rows.Count; j++)
{
Row.Clear();
for (int i = 0; i < dpExport.Columns.Count; i++)
{
if (!Convert.IsDBNull(dpExport.Rows[j][i].ToString()))
{
data = dpExport.Rows[j][i].ToString();
data = data.Replace("\"", "\"");
Row.Add(data.ToString());
}
}
dtExport.Rows.Add(Row.ToArray());
}
Let's do this !
|
|
|
|
|
OK, now it seems that we cannot update the dpExport within the loop.
Try caching the rows to a local collection and after the loop update all the rows in the cache.
I don't know if this helps.
Sunny Chen
===============================================
System Analyst, System Architect
Consultant of China System Analyst Institution
http://www.sunnychen.org
===============================================
|
|
|
|
|
i am trying to update a mdb file.
i added a new rows to the dataset and now i am trying to update a empty mdb file to the content of the dataset.
i did something but i received an exception:
The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data.
my code is:
string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Dir;
string commandString = "Select id,name from table";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(commandString, connectionString);
My_DataSet = new DataSet();
OleDbCommandBuilder cb = new OleDbCommandBuilder(dataAdapter);
dataAdapter.Fill(My_DataSet, "Events");
dataAdapter.Update(My_DataSet, "Events");
|
|
|
|
|
Or try making the field bigger.
|
|
|
|
|
You can pretty much narrow this down to one of the Text columns. Compare the size of the columns with what you are trying to enter into them. If you didn't set a specific size for the column when you made it, it will default to 50 characters.
The other thing you might want to double check is the order in which you have added the parameters. It must exactly follow the order in which they appear in the SQL. otherwise the value of one might be trying to get inserted into the wrong column, which would cause this error.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank you! that was perfect
|
|
|
|
|
Hi
I need to generate a 32 bit network address with the following rules: Can anyone help me with this.
1. There must be at least 1 level change in every 3 consecutive bits
i.e. ...100101110100... is acceptable
.....10010111100... is not acceptable, as it contains 4 consecutive 1's
2. Each of the 4 bytes making up the 32 bit address must be unique.
|
|
|
|
|
generate each bit sequentially running a counter to detect too many consecutive digits. If two bytes end up identical discard the second and regenerate.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
That could be a good Friday Programming Quiz... see if the Linq experts can find a way to do it.
|
|
|
|
|
i have the following,i'm generating a 32bit alphanumeric number,how to i check for my criteria?
GenerateRandomNumbers(1,7);
private string GenerateRandomNumbers(int Count, int Precision)
{
System.Text.StringBuilder numberBuilder = new System.Text.StringBuilder();
System.Text.StringBuilder numberString = new System.Text.StringBuilder();
string newNumber;
for (int loop=0; loop < Count; loop++)
{
numberBuilder.Length = 0;
while (numberBuilder.ToString().Length < Precision)
{
numberBuilder.Append(System.Guid.NewGuid().ToString().Replace("-", ""));
}
newNumber = numberBuilder.ToString();
if (newNumber.Length > Precision)
{
newNumber = newNumber.Substring(0, Precision);
}
numberString.Append((loop + 1).ToString());
numberString.Append(newNumber.ToUpper());
if ((loop+1) < Count) { numberString.Append(", "); }
}
return numberString.ToString();
}
|
|
|
|
|
After giving it more thought... First begin with the bytes that don't have three consecutive digits, there are only sixty-eight of them:
00100100 36
00100101 37
00100110 38
00101001 41
00101010 42
00101011 43
00101100 44
00101101 45
00110010 50
00110011 51
00110100 52
00110101 53
00110110 54
01001001 73
01001010 74
01001011 75
01001100 76
01001101 77
01010010 82
01010011 83
01010100 84
01010101 85
01010110 86
01011001 89
01011010 90
01011011 91
01100100 100
01100101 101
01100110 102
01101001 105
01101010 106
01101011 107
01101100 108
01101101 109
10010010 146
10010011 147
10010100 148
10010101 149
10010110 150
10011001 153
10011010 154
10011011 155
10100100 164
10100101 165
10100110 166
10101001 169
10101010 170
10101011 171
10101100 172
10101101 173
10110010 178
10110011 179
10110100 180
10110101 181
10110110 182
11001001 201
11001010 202
11001011 203
11001100 204
11001101 205
11010010 210
11010011 211
11010100 212
11010101 213
11010110 214
11011001 217
11011010 218
11011011 219
Put these in a collection (an array perhaps), grab one at random. Grab another, if the first ends with a double-digit and the second begins with the same double-digit, then try again.
You don't say whether or not using the same byte twice is allowed.
|
|
|
|
|
im a relative noob when it comes to code, im more of a creative 3d designer but as part of my uni course i do need to create a working 2d side scrolling shooter like metal slug using visual studio, direct X 9 in C#... i can use a games engine if i wish as they want to concentrate on my creative skills rather then code work...
SO a couple of questions i have for you very fine people...
---I need a minimum spec for a PC that can run this game, its going to be very simple with only 3 levels and simple 16 bit colours any ideas?
--- Does anyone know of a nice games engine that i can run in VS.
cheers guys...
sam
|
|
|
|
|
|
cheers mate, thats pretty much perfect
|
|
|
|
|
Hi all,
It seems an application i'm working on has developed a problem. My colleague has created a user control which inherits the ListView control so we can implement an edit in place feature.
The edit in place feature simply listens for an event when you click on a rows subitem and if its the cell you want to edit, it will move and resize a textbox over the cell and pull the value.
An event (endediting) is fired when the control looses focus or a certain key is pressed. We use this event do what we want with the value typed in.
This seems to work fine unless you stick in something that causes the listview to loose focus whilst within this event. I am attempting to parse the value typed in and if its invalid, I am throwing an error (messagebox) to notifiy the user and setting the cancel flag (e.Cancel.)
If I use the mouse to click the OK button within the MessageBox, when it disappears an Rubberband appears on my cursor and remains inside the listview. The only way to remove this is to either click the mouse, alt+tab to cause the form to invalidate or press escape.
If I use the enter or escape key to clear the MessageBox, the above doesn't happen and the listview regains focus.
I'm now at a loss, I have no idea where to turn I have tried invalidating the form, the listview etc, i've tried forcing the focus of all of the controls within the same form and i've even tried sending the escape key to the app using sendkeys.
Has anyone got any idea's why? I'd appreciate your input!
Regards
|
|
|
|
|
Well i've resolved it.
By setting the following properties, it no longer causes the undesired effect.
FullRowSelect = true;
HeaderStyle = NonClickable;
HideSelection = false;
MultiSelect = false;
|
|
|
|
|
Hi
I am using Visual Studio 2005 and C# to develop a Windows application.
When the columns in a DataGridView are ordered, it seems as if only the DisplayIndex changes. Is there a way to also change the actual ColumnIndex in the DataGridView (as well as the columns in the DataTable that is bound to the DataGridView) when ordering the columns in the DataGridView?
The reason I want to do this is because the DataTable is sent to another Form as well where it is bound to another DataGridView. Here I would like the column order to reflect the way it was changed on the first form.
Thanks.
Kobus
|
|
|
|
|
only thing that I can suggest is to sort the datatable whenever the user sorts grid column. But I am least confident that I will work.
|
|
|
|