|
To add to this most excellent reply, they also aid with encapsulation. Because you expose a method rather than a field with get, set, the implementing class can replace the internal implementation of the property without affecting the outside world. If your class keeps a hard count of elements in a tree (say) and exposes that via "public int count" then it must retain that count for all time. If it is exposed via
public int Count
{
get { return count; }
set {count = value; }
}
then it is at liberty to dispose of the "count" field and replace it with a new implementation at will. This will not affect classes relying on the "Count".
Further, it allow you to error check the assignments:
public int Count
{
get { return count; }
set
{
if ((value < 100) && (count >= 0))
{
count = value;
}
else
{
throw new Exception(string.Format("Value out of range: {0}", value));
}
}
}
But I agree - read a book, because if you don't know this stuff, there are a lot of other complexities you need to be aware of before you go much further!
Good luck.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
HOw i Display CSV File Data TO DataGridView
Please Help me With Connection string And Code.
|
|
|
|
|
Hi!!!
Try to do some research by yourself instead of asking code from others....
have a look at this site....
csv to datatable[^]
Can give you some insight regarding the issue....
Have a Happy Coding.....
|
|
|
|
|
I have tried it But i got Error Path is not correct even i give it to right path
here is my code
string Con_Str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My\a.csv;Extended Properties=Text;HDR=No;FMT=Delimited";
OleDbConnection cn = new OleDbConnection(Con_Str);
cmd=new OleDbCommand("select * from Book1.CSV",cn );
da=new OleDbDataAdapter(cmd);
ds=new DataSet();
da.Fill(ds,"ex");
dataGridView1.DataSource=ds.Tables[0].DefaultView;
|
|
|
|
|
So what's the filename of your CSV file?? In your code you have, in the connection string, C:\My\a.csv. But, in the OleDbCommand, you have Book1.CSV. So, which is it??
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
using System.Security.Cryptography;
public DataSet ExcelToDS(string Path)
{
//return one dataset
object missing = Missing.Value;
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = false;
try
{
excelApp.Workbooks.Open(path, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
excelApp.Workbooks[1].Worksheets[i + 1];
Excel.Worksheet ws = (Excel.Worksheet)excelApp.Workbooks[1].Worksheets[1];
string sheetName = ws.Name;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [" + sheetName + "$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds);
conn.Close();
excelApp.Workbooks.Close();
excelApp.Quit();
excelApp = null;
return ds;
}
catch
{
MessageBox.Show("Not close EXCEL", "Err Info", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
KillProcess("EXCEL");
return null;
}
}
modified on Tuesday, May 5, 2009 3:52 AM
|
|
|
|
|
Hi ,
I am developing an application with a datagrid using which user can update the data in the datagrid row. Its all in ASP.Net c#.
on click of a button i should do the following.
Check if user has modified atleast one row.
1. If the user has not modified even one row, then i should display a messsage stating user to action atleast one row.--- I have done this check and works good.
2. If the user has changed atleast one row then i should display a alert asking for confirmation if they would like to proceed. If the user selects 'No' i should stop the execution. if he clicks Yes the execution should proceed. -- I need help on this .. I am not able to trigger it becuase the button is already clicked.
Please help me sort the point 2.
|
|
|
|
|
WE have an ASP.NET forum
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
if the useer click no whit action must be stopped?
modified on Tuesday, May 5, 2009 3:29 AM
|
|
|
|
|
On the click of yes the changes done by the user in datagrid is updated in databases. This should not happen if he clicks no.
|
|
|
|
|
if(MessegeBOx.Show("Are you sure?",...,MessageBoxBottunYesNo) == DialogResult.YES)
update();
else
return;
modified on Tuesday, May 5, 2009 3:28 AM
|
|
|
|
|
You'll using right to limit the buttom, and user right from userlevel list table.
|
|
|
|
|
Hi.
I have a question. Say you have a database with 10 tables, they all are related to each other. Now you start your Windows application and obviously you implement a typed dataset to enable offline work etc.
My question is this, is it better to create a few datasets or just one? Can I create a dataset for each table in the database?
Illegal Operation
|
|
|
|
|
Illegal Operation wrote: Can I create a dataset for each table in the database?
A DataSet can contain many tables, so creating separate dataset for each tables is not required.
|
|
|
|
|
DataSet has DataTableCollection, DataRelationCollection and ExtendedProperties using which you can store multiple tables inside a dataset. So there is no need use multiple datasets.
Either you love IT or leave IT...
|
|
|
|
|
I had small application of BHO in c#, when the events gets fired I used perform the operation that I
want to do on browser(IE). The thing is I want to know the header information? as the data gets loaded
on browser packet by packet, how can I know these header information regarding content length,
content-type that the data gets loadad on IE.
Thus how can I know header information through BHO?
|
|
|
|
|
Hi,
I am having some trouble debugging a windows service. i have attached a debugger to the service but after each change, do i have to rebuild my windows service, rebuild setup and uninstall and install the service. There must be an easy approach to this.
Please provide help
|
|
|
|
|
Solution explorer -> Right click on project -> Debug -> Choose any option
|
|
|
|
|
I have a datagridView in a winform and i display the results of a particular search. How do I highlight/bold only the charecters or the substring in the cell that matches my search.
(the best analogy would be the google finance, in which as you type ahead it bolds the characters that match the search)
thanks.
|
|
|
|
|
I have a image button in a winform. On mouse hover i would like to change the image of the button. When the focus is lost i would like to show the original image .
I am handling the mouse_hover and mouse_leave events and changing the value of image property to the image i need. My images are stored in the resource file.
Is this the right way to do it?
Please let me know..
|
|
|
|
|
Yeah, that seems the best way to me.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
you can use a imageList and insert your images into it and on mouse events change button imageIndexes for example:
mybutton.ImageIndex = 0;
|
|
|
|
|
Hello,
i am assigned to work on a windows service developed by another programmer. I am having problems attaching to the windows service. the service was communicating with a remote server and for testing purposes, i want it to work on my local host.Whenever i get disconnected from LAN, it won't run probably because it can't make a connection to server, but i want to insert a breakpoint right at the beginning so whenever i find a connection to remote server, i change it. this didn't work,
so i thought of uninstalling the current service and installing a new instance of it with local host only, But i am having the following probs.///i don't know the exact path. solution (folder)has been pasted to another location
c:\Program Files\Microsoft Visual Studio 9.0\VC>installutil /u marketordermanage
r.exe
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///c:\Pro
gram Files\Microsoft Visual Studio 9.0\VC\marketordermanager.exe' or one of its
dependencies. The system cannot find the file specified..
i don't have it in controlpanel\add or remove programs...
i even tried the sc command, it didnt work. how do i delete this service.
thanx inadvance
|
|
|
|
|
I think if you use "service" control in cs you can solve your problem.
|
|
|
|