|
<br />
private void open_Database(string XML_DB_Name)<br />
{<br />
dataSet.ReadXml(XML_DB_Name);<br />
DataTable dt = dataSet.Tables[0];<br />
string tblName = dt.TableName;<br />
currentTable = dataSet.Tables[tblName];<br />
dataGrid1.SetDataBinding(dataSet, tblName);<br />
dataGrid1.CaptionText = tblName;<br />
<br />
DataRow MyRow = currentTable.Rows[0]; <---- Problem when currentTable is empty, i get an exception...probably i can get the RowCount in another way?<br />
int RowCount = MyRow.Table.Rows.Count;<br />
<br />
foreach(DataTable dTable in dataSet.Tables)<br />
{<br />
DataGridTableStyle dgStyle = new DataGridTableStyle();<br />
dgStyle.MappingName = dTable.TableName;<br />
if(RowCount < 8)<br />
{<br />
dgStyle.PreferredColumnWidth = 120;<br />
}<br />
else<br />
{<br />
dgStyle.PreferredColumnWidth = 110;<br />
}<br />
dataGrid1.TableStyles.Add(dgStyle);<br />
}<br />
}<br />
i get this exception:
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll
Additional information: There is no row at position 0.
But i want to have the rowcount also when its 0!!
cu
|
|
|
|
|
surfman19 wrote:
DataTable dt = dataSet.Tables[0];
surfman19 wrote:
DataRow MyRow = currentTable.Rows[0]; <---- Problem when currentTable is empty, i get an
An array has to have at least 1 variable placeholder. Make the [0] to [1].
|
|
|
|
|
In most C style languages like C#, array indexes usually start with 0 rather then 1. For loops usually follow this form.
for(int i=0; i<list.count; ++i)
="" do="" something="" with="" list[i]="" here=""
<hr=""> I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
if (currentTable.Rows.Count > 0)
{
}
Should help
Gary
Marc Clifton: "In other words, VB is like a bad parent. It can really screw up your childhood."
|
|
|
|
|
solved:
<br />
int RowCount = dt.Rows.Count;<br />
cu
|
|
|
|
|
I have a file that has a serialized object in it.
I wrote ANOTHER program that I wanted to read that object.
When I attempt to Deserialize I get the following execption:
Unable to find assemble 'Address, Version 1.0.0.0, Culture=neutral, PublicKeyToken=null
To make sure the second program new about the class object that was stored in the file, I copied the class to the new program. I also copied the Serialize and Deserialize code that works on the first program to the second program. The first program can read and write with no problems to this file. Both programs were created in MS's Visual C# 2005 Express Edition Beta.
Anybody have an idea why one program can not read a serialized file created by another program?
Thanks for any help,
Dave
|
|
|
|
|
You can't copy a class by coping the source code for it. That will only create a class that looks exactly the same, but it is not the same class.
Compile the class by itself, so that you can reference the dll from both programs.
---
b { font-weight: normal; }
|
|
|
|
|
That still wont work. According to MSDN, a serialized stream will NOT deserialize in any program except the one that serialized it. Maybe of your new program has the same assembly name and such it may work.
I searched for days for this answer until I came scross that on MSDN.
|
|
|
|
|
Does anyone know how to make DebugView from SysInternals "work"? I am trying to write a C# program in .NET 2003 and to print 2 lines:
System.Diagnostics.Debug.WriteLine("I am debugging");
System.Diagnostics.Trace.WriteLine("I am Tracing"); I start dbgview.exe, run my program, and I do not see those comments (I checked that I am in debug mode). I have seen references to some kind of TraceListener, but I don't know what that is or where to set it up.
If anyone knows what I'm talking about, could you please link me to some pertinent info? My quick search on google didn't give me anything.
Thanks
Sue
|
|
|
|
|
|
Thanks very much for the link. I can't seem to get it working yet, but I will keep looking around here.
I put in a TextWriterTraceListener, and that does nothing;
I put in an EventLogTraceListener, and that properly writes to the Event Log;
I put in a DefaultTraceListener, and that throws an error.
Thanks for the help.
Sue
|
|
|
|
|
That's surprising. AFAIK, TraceListeners are useful if you want to monitor trace output within your application, they notify you when someone does a Trace.WriteLine or something similar.
You should be seeing the messages in DebugView without doing anything special. Are you able to see the messages in VS .NET's Output window?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I did not realize I could see the output there . I fired it up, and yes, I can see the output in the output window.
I still cannot see it in DebugView though! I tried the suggestion from the other poster to add a trace listener app.config section but that didn't seem to work.
I can get a lot of information, though, just by using the output window. Man, I feel like an amateur!
|
|
|
|
|
string[] skills = new string[1];<br />
skills[0] = "attack";<br />
<br />
<br />
DataTable dtshowskills = new DataTable("USkills");<br />
<br />
DataColumn userSkill = new DataColumn("Skill");<br />
dtshowskills.Columns.Add("userSkill");<br />
DataColumn userLevel = new DataColumn("Level");<br />
dtshowskills.Columns.Add("userLevel");<br />
<br />
foreach (string skill in skills)<br />
{<br />
DataRow drskill = dtshowskills.NewRow();<br />
drskill["userSkill"] = skill;<br />
drskill["userLevel"] = 0;<br />
dtshowskills.Rows.Add(drskill);<br />
}<br />
<br />
dgSkills.DataSource = dtshowskills;<br />
dgSkills.DataBind();
<asp:DataGrid ID="dgSkills" Runat="server" />
I don't understand DataTables, and I am going to do some reading up on them, but for now, someone please help me. I had help on most of it a while ago, any help is appricated.
|
|
|
|
|
I'm not sure what error you are getting since you didn't list it, but I'm guessing it is because you havne't set the data types of the DataColumns. Post the problem and we can help you out.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Oops, sorry I thought that I did post the error. My bad. Here is the error:
System.NullReferenceException: Object reference not set to an instance of an object.
|
|
|
|
|
DataColumn userSkill = new DataColumn("Skill");
dtshowskills.Columns.Add("userSkill");
DataColumn userLevel = new DataColumn("Level");
dtshowskills.Columns.Add("userLevel");
foreach (string skill in skills)
{
DataRow drskill = dtshowskills.NewRow();
drskill["userSkill"] = skill;
drskill["userLevel"] = 0;
dtshowskills.Rows.Add(drskill);
}
should instead read
DataColumn userSkill = new DataColumn("Skill");
dtshowskills.Columns.Add(userSkill);
DataColumn userLevel = new DataColumn("Level");
dtshowskills.Columns.Add(userLevel);
foreach (string skill in skills)
{
DataRow drskill = dtshowskills.NewRow();
drskill["Skill"] = skill;
drskill["Level"] = 0;
dtshowskills.Rows.Add(drskill);
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
You are creating DataColumn objects, but you don't use them. Instead you create columns that have the same name as the variables. To use the DataColumn objects that you create, do like this:
DataColumn userSkill = new DataColumn("Skill");<br />
dtshowskills.Columns.Add(userSkill);<br />
DataColumn userLevel = new DataColumn("Level");<br />
dtshowskills.Columns.Add(userLevel);
The columns will now be named "Skill" and "Level".
---
b { font-weight: normal; }
|
|
|
|
|
string[] skills = new string[1];<br />
skills[0] = "attack";<br />
<br />
<br />
DataTable dtshowskills = new DataTable("USkills");<br />
<br />
DataColumn dcuserSkill = new DataColumn("Skill");<br />
dcuserSkill.DataType = System.Type.GetType("System.String");<br />
dtshowskills.Columns.Add(dcuserSkill);<br />
DataColumn dcuserLevel = new DataColumn("Level");<br />
dcuserLevel.DataType = System.Type.GetType("System.Int32");<br />
dtshowskills.Columns.Add(dcuserLevel);<br />
<br />
foreach (string skill in skills)<br />
{<br />
DataRow drskill = dtshowskills.NewRow();<br />
drskill["Skill"] = skill;<br />
drskill["Level"] = 0;<br />
dtshowskills.Rows.Add(drskill);<br />
}<br />
<br />
dgSkills.DataSource = dtshowskills;<br />
dgSkills.DataBind();
Error is now:
System.NullReferenceException: Object reference not set to an instance of an object.
|
|
|
|
|
I checked your code. It works just fine. Can you debug your code and tell us exactly in which line you get the error.
Live Life King Size
Alomgir Miah
|
|
|
|
|
My debugger doesn't work, it has a problem doing remote debugging, how do I set that up?
|
|
|
|
|
Hi all,
I need to make a pie chart in Excel but cant find the correct constant!
Excel.Constants.xl3DBar is available but not xl3DPie!
When I run the macro tool on Excel it uses the constant xl3DPie but when I try to use it in my C# code I get an error.
Any ideas?
schoudhr@hotmail.com
|
|
|
|
|
I brought this up a few days ago. However, I have yet to find a solution that fits my needs. I need a textbox to display : "00:00:00" for hours minutes and seconds. I need this format to be "locked." Therefore, not allowing the user to change the format. Each colon would be static. Any help would be much appreciated. Thanks
D
|
|
|
|
|
You need to use masked textbox search for one to get your request or use the following class as start to develop your one.this class will masked by 00:00:00
public class MaskedTextBox : TextBox
{
private string mask;
public string Mask
{
get
{
return mask;
}
set
{
mask = value;
this.Text = mask;
}
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (Mask != "")
{
e.Handled = true;
string newText = this.Text;
bool finished = false;
for (int i = this.SelectionStart; i < mask.Length; i++)
{
switch (mask[i].ToString())
{
case "0" :
if (Char.IsDigit(e.KeyChar) )
{
if(this.TextLength < mask.Length)
{
newText += e.KeyChar.ToString();
finished = true;
break;
}
else
{
newText=newText.Remove(i,this.SelectionLength);
newText=newText.Insert(i,e.KeyChar.ToString());
finished = true;
break;
}
}
else
{
return;
}
default :
newText += mask[i];
break;
}
if (finished)
{ break; }
}
this.Text = newText;
this.SelectionStart = this.Text.Length;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
e.Handled = true;
}
}
Create instance from this class and set its mask property
maskedText.Mask="00:00:00"; Note: you need to add more code to handle other keys like bakspase and other things
MCAD
-- modified at 20:49 Friday 9th September, 2005
|
|
|
|
|
Hello,
How can I remove all new lines from some text typed by the user in a multiline TextBox ? He must enter some long text, so I want it wrapped in several lines, but if he presses Enter (or Ctrl+Enter), I want to remove the new line at the end.
I could go searching the string for all Environment.NewLine (or '\n' and '\r' ) but I would think there's a more efficient way.
Any ideas? Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|