|
Yay!!
One more item of my list of things to do in 2009.
|
|
|
|
|
Hi guys.
I've added a database in my project. VS2008 SP1 creates a DataSet with Database1DataSet name.
Now I want to update the DataBase with this code :
private void saveButton_Click(object sender, RoutedEventArgs e)
{
Database1DataSet myDataSet = new Database1DataSet();
DataRow myDataRow = myDataSet.Tables["events"].NewRow(); myDataRow["event"] = "new text";
myDataRow["date"] = mdCalendar.Time();
myDataSet.Tables["events"].Rows.Add(myDataRow);
}
but this error has occurred :
Object reference not set to an instance of an object.
I'm sure the events exist in the DataBase.
What's wrong with it ?
Thanks in advance.
|
|
|
|
|
Mohammad Dayyan wrote: Database1DataSet myDataSet = new Database1DataSet();
Since you're creating a new, fresh dataset it may not have any tables in it (depending what you do in the constructor for Database1DataSet).
Without knowing your program logic most likely you should refer to an existing dataset which is defined somewhere in the program (at form level, a static object etc.)
|
|
|
|
|
You create a .Net DataSet in memory, and immediately you do:
myDataSet.Tables["events"].NewRow();//on this line
Don't you think that your forgot to create a DataTable called "events" ?
You are not accessing any Database here, you are instantiating a DataSet object and you attempt to access a DataTable that you don't have created. I suggest reading some article about ADO.Net, it explains very well how to connect to a Database, retrieve data from it encaspulated in a DataSet, update data and stuff like that.
Jean-Christophe Grégoire
|
|
|
|
|
Thanks.
I've done it.
Database1DataSetTableAdapters.eventsTableTableAdapter eventsTableTableAdapte =
new WpfApplication1.Database1DataSetTableAdapters.eventsTableTableAdapter();
Database1DataSet.eventsTableDataTable eventsTableDataTable =
new Database1DataSet.eventsTableDataTable();
eventsTableTableAdapte.Fill(eventsTableDataTable);
DataRow newDataRow = eventsTableDataTable.NewRow();
newDataRow["event"] = "event8" ;
newDataRow["date"] = 654982;
eventsTableDataTable.Rows.Add(newDataRow);
eventsTableTableAdapte.Update(eventsTableDataTable);
eventsTableTableAdapte.Dispose();
eventsTableDataTable.Dispose();
But I don't know why the changes haven't applied to the DataBase
Could you guide me ?
|
|
|
|
|
Can CollectionEditor properties be set programmatically please?
For example, I have two CollectionEditor properties 'AutoWidth'(bool) and 'ColumnWidth'(int).
If 'AutoWidth' is set to 'True' then I would like the property 'Column Width' to be disabled.
|
|
|
|
|
I don't know if this can be done but I am sure that someone else will provide help if it can.
What I would say is that if you look at similar properties in the inbuilt controls e.g. AutoSize for labels, textboxes etc. they do not disable other properties when set. The program logic just ignores changes to the irrelevant properties if they (AutoSize) are set to true.
So in the setter for ColumnWidth only apply setting if AutoWidth is false.
something like:
public int ColumnWidth
{
get
{
return this.columnWidth;
}
set
{
if (!this.autoSize)
{
if (this.columnWidth != value)
{
this.columnWidth = value;
this.Invalidate();
}
}
}
}
Hope this helps.
Honi soit qui mal y pongs - Evil to he who thinks it stinks
|
|
|
|
|
A good point well made.
Much appreciated.
As an aside, I notice that items like 'DataSource' in component properties are intially set to '(none)'. As yet, I have not figured out how to do this for my own (custom) properties. If anyone knows this I would be grateful for an educational 'nudge'.
|
|
|
|
|
Google, or otherwise search) for info on the AttributeProvider attribute.
Come back if still no joy.
Honi soit qui mal y pongs - Evil to he who thinks it stinks
|
|
|
|
|
|
i have developed a apps and in that apps a timer is there and i am showing ShowBalloonTip repeatedly from a timer method but the problem is ShowBalloonTip not showing. my timer elapsed time is 30 seconds.
from my timer tick method i have written code like
objNotifyer.Text = "MyMessage";
objNotifyer.ShowBalloonTip(1, "Info", "MyMessage", ToolTipIcon.Info);
i just can not understand why balloon is not showing. so please guide me regarding this and if possible then tell me how to write the code which will repeatedly show the balloon message from my timer tick method. please help.
tbhattacharjee
|
|
|
|
|
Try adding objNotifyer.Visible = true before ShowBalloonTip.
|
|
|
|
|
Hello All!
I have created a control that inherits from a Panel. My control has a method, UpdateControls() that repositions all of its child controls to where they need to be after they’ve been resized.
Sometimes the resizing causes the Vertical and Horizontal scroll bars to appear. I want the Vertical, but not the Horizontal, so at the end of the UpdateControls() method my control checks to see if the Vertical scroll is visible, and if it is, it increases its width so the Horizontal scroll bar isn’t needed.
protected void UpdateControls()
{
this.SuspendLayout();
int LastTop = this.AutoScrollPosition.Y;
foreach (Control ic in _controls)
{
ic.Top = LastTop;
LastTop = ic.Bottom + 5;
}
this.ResumeLayout(true);
if (this.Width != this.NeededWidth)
{
this.Width = NeededWidth;
}
}
public int NeededWidth
{
get
{
if (this.VScroll)
return _MaxWidth + 17;
else
return _MaxWidth;
}
}
However, the form that contains my control isn’t updated properly. It seems to lag behind by one UpdateControls() call. It seems as though the resize of my control isn’t taking place until after all of the painting is done.
I’ve tried calling this.parent.Invalidate(true) and this.parent.Refresh() at the end of my UpdateControls() method, but neither force the new size to be used.
I found that by listening to the MyControl.SizeChanged event in MyForm and re-assigning the new width (after it had already been updated, thus triggering the SizeChanged event) will force the new size to be used, but MyControl gets drawn twice and it is noticeable on my form.
_ItemsContainer = new MyControl();
_ItemsContainer.SizeChanged += new EventHandler(_ItemsContainer_SizeChanged);
...
void _ItemsContainer_SizeChanged(object sender, EventArgs e)
{
_ItemsContainer.Width = _ItemsContainer.NeededWidth;
}
How can I force the new size to be used so the Horizontal Scroll bars aren’t being drawn in my control?
Thank you!
|
|
|
|
|
Edit:
I had this problem when dealing with panels, what I did was keep all the panals inside my control visible = false, add the controls to each sub panel inside my panel and then reset the main panels height and width, then toggled all controls inside to visible=true as needed (it was a menu based off a data table, might not be exactly what you are looking for) then call the forms Update method after adding controls to my panels
|
|
|
|
|
After further auditing of my old code (your post had me refactor it a bit) I see that I set the visibility of the panel to false, added all the controls, resized it then set visibility to true, that was there is no visible horizontal / vertical bars appearing to the user as its visibility was off.
Let me know if I'm off base with this over here.
|
|
|
|
|
Why don't you just set the child control anchor properties correctly and be done with it?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Setting the anchor to Left | Right worked.
Thanks everybody!
|
|
|
|
|
Hi all,
i need to send a data message to a device every data message must have its header.
byte[] messageheader;
messageheader= new byte[10];
messageheader[0] = 0x16;
messageheader[1] = 0x01;
messageheader= BitConverter.GetBytes(01);
messagehd[3] = 02;
messageheader[4] = 00;
messageheader[5] = (byte)(message.Length);
serialPort1.Write(messageheader, 0, messageheader.Length);
now the BitConverter delete every thing, i think this is very simple, but I'm struggling with it
thanks in advance.
modified on Wednesday, January 7, 2009 3:31 AM
|
|
|
|
|
A4ad wrote: messageheader= BitConverter.GetBytes(01); // this must be divided into two bytes within the array
Since BitConverter.GetBytes() returns an array, your messageheader gets reassigned, thus losing the reference created 3 lines above. What you need to do is:
byte[] messageheader = new byte[10];
messageheader[0] = 0x16;
messageheader[1] = 0x01;
Array.Copy(BitConverter.GetBytes(01), 0, messageheader, 2, 2);
messagehd[4] = 02;
messageheader[5] = 00;
messageheader[6] = (byte)(message.Length);
serialPort1.Write(messagehd, 0, messagehd.Length);
|
|
|
|
|
thank u for your answer, it helps me a lot...
but is it an issue if id do the array copy, for the whole array. i don't think it will effect the performances of my application, but it looks to me that is not the write way to do this for the array.
|
|
|
|
|
The performance difference between copying 2 bytes and 4 bytes is insignificant, but you should take the habit of not doing more than necessary.
|
|
|
|
|
Please for good people - only - how to change computer name by c# , i found many codes but all is not working well.
thanks & regards
|
|
|
|
|
|
Hi,
SetComputerNameEx[^] should do it, however you must restart the system to make it work!
|
|
|
|
|
Dear All,
I have created a setup project using vs 2005 and i want to install another .exe file after finishing my c# application setup.I am getting the .exe file as embeded resource to my project.
now using Installer when i use to run the .exe file after installation, it gives me an error file not found. I know the Error is that it can not locate or find the .exe file which i am installing after c# application.
I am asking how to get the installation path (folder which i am installing the application)?
I use Application.startup, but it did not help.
Remember that the .exe file which i am installing is inside that installation folder.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|