|
you can use OLEDB text reader to connect to the text file and get its contents in a datatable and set that datable as datasource for the datagrid.
something like:
<br />
<br />
Dim str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\textfilepath\;Extended Properties='text;HDR=Yes;FMT=Delimited'" ' HDR=No if textfile deos not have header row<br />
<br />
Dim conn As OleDbConnection<br />
Dim da As OleDbDataAdapter<br />
conn = New OleDbConnection(str)<br />
<br />
strSql = "select * from textfilename.txt" ' or .csv<br />
da = New OleDbDataAdapter(strSql, conn)<br />
dtable = New DataTable("kkinvoices")<br />
da.Fill(dtable)<br />
datagrid.datasource=dt<br />
datagrid.databind()<br />
check this[^] for complete connection string...
-----
|
|
|
|
|
Woah, thats not C#, thats VB.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
I know that.. because I had the code in VB. so I just posted.. its not difficult at all to convert it to C#;P
-----
|
|
|
|
|
Fair enough
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
I all. I have a strange case with display timer
my code look like this:
Timer myTimer = new Timer();
public static int nr = 1;
private void button1_Click(object sender, EventArgs e)
{
myTimer.Interval = 1000;
myTimer.Enabled = true;
myTimer.Start();
myTimer.Tick += new EventHandler(myTimer_Tick);
}
void myTimer_Tick(object sender, EventArgs e)
{
string a = "";
int tid1 = 0;
int tid2 = 0;
a = label21.Text;
tid1 = Convert.ToInt32(a);
tid2 = (int)tid1 - nr;
label21.Text = tid2.ToString();
}
But if i click on a stop button with:(myTimer.Stop()), then when i press on play button again the string (nr) has change to 2 and next time 3
How do i make this work??
Anyone with a good idea??
Tnx!!!
|
|
|
|
|
Almost no textbook or college course teaches you to use a debugger.
But you should.
Try selecting the first line in myTimer_Tick(), hit F9 to set a breakpoint, then run the program. When it stops there, put your mouse over the variables or look at the Watch box to see what the values are on the variables. Then execute one line at a time (Debug -> Step Over) and figure out what's wrong.
It's a really good way to fix problems and learn programming.
By the way, what exactly are you trying to do?
|
|
|
|
|
First of all : Avoid declaring many variables. So
Instead of
void myTimer_Tick(object sender, EventArgs e)<br />
{<br />
string a = "";<br />
int tid1 = 0;<br />
int tid2 = 0;<br />
a = label21.Text;<br />
tid1 = Convert.ToInt32(a);<br />
tid2 = (int)tid1 - nr;<br />
label21.Text = tid2.ToString();<br />
}
You can just use which is more readable.
void myTimer_Tick(object sender, EventArgs e)<br />
{<br />
label21.Text = (Convert.ToInt32(label21.Text) - nr).ToString();<br />
}
We can understand that you are decrementing a number and displaying it in a textBox.
Your question is "string (nr) has change to 2 and next time 3".
- nr is not a string, nr is a static int So what do you mean by this?
Do you mean the text is being incremented instead of decrementing. Well this is impossible as you see that there is no addition code in myTimer_Tick().
Best Regards.
|
|
|
|
|
Hey All,
I am trying to run a C# GUI Form on Fedora 8 using mono. If I run console applications, everything runs fine, but if I try to run a simple GUI application, I get the following exception (by the way, I didn't have to install mono, since it came with Fedora 8, but my guess is I am missing a graphic component needed to run GUI forms):
<br />
mono HelloWorldGUICS.exe<br />
<br />
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.Form ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: gdiplus.dll<br />
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)<br />
at System.Drawing.GDIPlus..cctor () [0x00000] --- End of inner exception stack trace ---<br />
<br />
at <0x00000> <unknown method><br />
at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] <br />
at System.Drawing.Image..ctor (System.Runtime.Serialization.SerializationInfo info, StreamingContext context) [0x00000] <br />
at System.Drawing.Bitmap..ctor (System.Runtime.Serialization.SerializationInfo info, StreamingContext context) [0x00000] <br />
at <0x00000> <unknown method><br />
at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[])<br />
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] --- End of inner exception stack trace ---<br />
<br />
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] <br />
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] <br />
at System.Runtime.Serialization.ObjectRecord.LoadData (System.Runtime.Serialization.ObjectManager manager, ISurrogateSelector selector, StreamingContext context) [0x00000] <br />
at System.Runtime.Serialization.ObjectManager.DoFixups () [0x00000] <br />
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000] <br />
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] <br />
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] <br />
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] <br />
at System.Resources.ResourceReader.ReadNonPredefinedValue (System.Type exp_type) [0x00000] <br />
at System.Resources.ResourceReader.ReadValueVer1 (System.Type type) [0x00000] <br />
at System.Resources.ResourceReader.ResourceValue (Int32 index) [0x00000] <br />
at System.Resources.ResourceReader+ResourceEnumerator.get_Value () [0x00000] <br />
at System.Resources.ResourceSet.ReadResources () [0x00000] <br />
at System.Resources.ResourceSet.GetObject (System.String name, Boolean ignoreCase) [0x00000] <br />
at System.Resources.ResourceManager.GetObject (System.String name, System.Globalization.CultureInfo culture) [0x00000] <br />
at System.Resources.ResourceManager.GetObject (System.String name) [0x00000] <br />
at System.Windows.Forms.Locale.GetResource (System.String name) [0x00000] <br />
at System.Windows.Forms.Form..cctor () [0x00000] --- End of inner exception stack trace ---<br />
<br />
at <0x00000> <unknown method><br />
at HelloWorldGUICS.Form1..ctor () [0x00000] <br />
at (wrapper remoting-invoke-with-check) HelloWorldGUICS.Form1:.ctor ()<br />
at HelloWorldGUICS.Form1.Main () [0x00000] <br />
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
DigiOz Multimedia wrote: System.DllNotFoundException: gdiplus.dll
As far as I can see, you're missing a DLL called gdiplus.dll.
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
If you are missing the GDI+ dll, that would explain why the error only happens with GUI apps. GDI+ is the whole drawing library thing that c# uses.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
The Undefeated wrote: If you are missing the GDI+ dll, that would explain why the error only happens with GUI apps. GDI+ is the whole drawing library thing that c# uses.
Found this article which seemed to explain at least one of the errors above:
http://www.mono-project.com/DllNotFoundException[^]
It didn't fix my problem though, because even though there was a GDI+ library at "/usr/lib", it was called "libgdiplus.so.0" and "libgdiplus.so.0.0.0" (wrong folder and wrong name).
I tried to reinstall the GDI+ library, but the machine froze and I had to reboot to get it back.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
DigiOz Multimedia wrote: If I run console applications, everything runs fine, but if I try to run a simple GUI application, I get the following exception
Finally found the solution to my problem. There was nothing wrong with GDI+, Mono or any other package on the system. The problem was Fedora 8s new Security System!! If I log in as root (not a good practice) and run the same application the GUI Application executes fine. So I think their new security system needs some more work.
Thank you everyone who tried to help.
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
Is there a way to convert a string type into a variable type: "string" > this."string"?
The effect I am looking for would be like the dynamic at runtime statement"this.'string' = 'the strings value'" sets a vaulue for the static compile time value "this.stringName"
Any comments or help?
Class MyClass
{
private string cn;
private string sn;
///I know.....not correct syntax
string this.cn = cn;
string this.sn = sn;
public void GetADObjectInfo(string dn)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://"+ dn);
foreach (string strAttrName in entry.Properties.PropertyNames)
{
try
{
this.cn = (string)result.Properties[cn][0];
//I want the above to become something like this
//this.strAttrName = (string)result.Properties[strAttName][0];
}
catch
{
}
}
}
}
with Regards,
shwa guy
-- modified at 12:18 Friday 23rd November, 2007
|
|
|
|
|
shwaguy wrote: Is there a way to convert a string type into a variable type: "string" > this."string"?
??? huh?
Can you rephrase your question?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
have a look at the System.Reflection namespace.
There are several articles about reflection here on CP.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
you actually understood what was meant? what was it?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
the question was: "If I have the name of an existing field/method/property in a string,
how can I access that particular field/method/property?"
or something completely different.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
ah! Well, I'm glad you were able to understand what was wanted, because I sure didn't!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
"Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
|
|
|
|
|
I have added a DataReceived event to COM3 (the IrDA port) on my PPC. However, this event is never fired. If I use a short Sleep function and then do a Read, the expected data is there. Does anyone have an idea of what is wrong here? My code follows.
public partial class Form1 : Form
{
private SerialPort m_gIrDA;
private Byte[] sendbuf;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
void m_gIrDA_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
MessageBox.Show("This never happens");
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (m_gIrDA != null)
{
m_gIrDA.Close();
}
m_gIrDA = new SerialPort("COM3", // string portName,
57600, // baudRate
Parity.None,
8, // int dataBits,
StopBits.One);
m_gIrDA.Handshake = Handshake.RequestToSend;
m_gIrDA.ReceivedBytesThreshold = 3;
m_gIrDA.DataReceived += new SerialDataReceivedEventHandler(m_gIrDA_DataReceived);
m_gIrDA.DtrEnable = true;
m_gIrDA.Handshake = Handshake.RequestToSend;
m_gIrDA.Open();
sendbuf = new byte[10];
sendbuf[0] = 0x0a;
sendbuf[1] = 0x00;
sendbuf[2] = 0x01;
sendbuf[3] = 0x20;
sendbuf[4] = 0x35;
sendbuf[5] = 0x38;
sendbuf[6] = 0x30;
sendbuf[7] = 0x30;
sendbuf[8] = 0xf9;
sendbuf[9] = 0xec;
m_gIrDA.Write(sendbuf, 0, 10);
}
catch (System.IO.IOException)
{
m_gIrDA.Close();
MessageBox.Show("IOException");
}
}
}
Steven L Berntsen
Montreal QC Canada
sberntsen@kim.kaba.com
|
|
|
|
|
Hi,
i like to know how can i know if the table exsits in a "FILE".mdb
using Odbc or OleDb.
THNKS
Have Fun
Never forget it
|
|
|
|
|
simplest way is to use the table name in select statement and catch the exception for FILE DOES NOT EXIST...
-----
|
|
|
|
|
THANKS, i Figured It Out
But THANKS For Answering
Have Fun
Never forget it
|
|
|
|
|
NotifyIcon Click Problem
I setup my NotifyIcon named "sysTray" as
<br />
class MainForm : Form<br />
{<br />
void setUpTrayIcon()<br />
{<br />
sysTray.Icon = Icon.ExtractAssociatedIcon("App.ico");<br />
<br />
this.Shown += delegate(object o, EventArgs ev)<br />
{<br />
sysTray.Visible = true;<br />
};<br />
sysTray.Click += new EventHandler(doSysClick);<br />
<br />
MenuItem[] itm = {new MenuItem("Prev", new EventHandler(doPrev)),<br />
new MenuItem("Next",new EventHandler(doNext)),<br />
new MenuItem("Stop", new EventHandler(doStop))};<br />
this.trayMenu = new ContextMenu(itm);<br />
<br />
sysTray.ContextMenu = this.trayMenu;<br />
}<br />
}<br />
The Icon showsup correctly in System Tray Area. When I Right Click on it the Menu also shows up. But once the Menu is Poped Up then It does not matter if I click on the Menu or My App's Tray Icon the sysTray.Click Item still gets Fired and my EventHandler, doSysClick is called.
What I expect is that Only when I click on the App Icon in the System Tray should my doSysClick method be called.
If My System Tray Menu is Visible then if I click anywhere outside it, then it should just hide itself (that is the usual behaviour).
So what am I missing?
Thanks...
|
|
|
|
|
Use the MouseClick, MouseDoubleClick etc... events instead of the general click event.
|
|
|
|
|
the Pronblem is i have a table of employeeinfo having attribuyes
EmpID
EmpName
EmpFatherName
GenID
now GenID is a primary key of a separate table having two attributes that is
GenID
Gender
the problem is when the form runs displaying 3 textboxes and one combobox the user must select the entry from gender and click save the values must be stored in the table of sql that is Employeeinfo i saved the first three attributes by the following code
datarow.["EmpID"] = EmpID.text;
but on GenID it gives problem bcoz i want to relate the Gender attribute to the GenID Attribute in the EmployeeInfo table and must be saved in the sql data table
|
|
|
|
|