|
|
Thank you very much for the answer, Peter, but OG's solution seems to work fine for me (and it is shorter).
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
|
Ooops... I overlooked that and posted it here, since I was having this problem in C#.
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
If you heard sounds, like someone muttering "tsk ... tsk ... tsk," it was not I
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
hi,
I am trying to SetValue for my registry ket at LocalMachine->Software->MyApplication but getting the following error:
Requested registry access is not allowed.
this is the code I am using:
RegistryKey regkeyLocalMachine = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MyPOSMachine", true);
regkeyLocalMachine.SetValue(value_name, value_data, value_kind);
and the error is thrown on the first line (the OpenSubKey).
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
You probably do not have the required permission to access the registry: write access requires Admin so your app may need elevation in order to work.
If you can, avoid using the registry - it is restricted now (and has been since Vista) and is likely to become more restricted in the future, not less.
If you can store your information elsewhere, then do: I tend to use a GUID app id folder below one of the public app data folders whenever I can: Where should I store my data?[^]
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
but can I use a file and still make it available for all user profile on the same computer or it will be per user and same configuration should be done again for every user on this computer?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Either: Environment.SpecialFolder.CommonApplicationData holds folders that are common to all users on a PC, while Environment.SpecialFolder.ApplicationData is user specific. I frequently use both, with a common GUID app ID folder name in each for the settings data.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
can I ask why GUID? why not the application name? any reason?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Application name may not be unique: a lot of the good ones are used already!
If you duplicate an existing app name, then it's quite likely that it's config info will interfere with yours or vice versa.
GUID's are less likely to be repeated, and harder for users to find and play with! If they don't need to access it manually, then why let them have an easy route?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I have two more questions please...
I assume the folder is writable and I don't nned special permission to write a file there even if the windows user is limited? correct?
what format you prefer to user for the file? XML?
Technology News @ www.JassimRahma.com
|
|
|
|
|
The folder is writable for all users with no special permissions required - that's kinda the whole point!
Format depends on what you are writing, and how you need it. XML is certainly an option, but I also use CSV, SqlCE, SqLite, and binary depending on what I need for the application. That's one of the reasons I wrote this: ByteArrayBuilder - a StringBuilder for Bytes[^] - it allows me to save complex data in a way that makes sense to the application classes, rather than rely on a data storage structure than may have to be kicked a few times to do what I wanted!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Great
Thanks
Technology News @ www.JassimRahma.com
|
|
|
|
|
You're welcome!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Hi all,i have a question about methods...
i want to write a method to connect my database and return a result like:
select * from mytable
and show it in a gridview control
how can i do it???
thank you...
|
|
|
|
|
You haven't stated what database you want to connect to. This article[^] describes the steps to connect an SQL Server database and will help you get started.
|
|
|
|
|
thank you...
i want to connect sql server database,
i have a class and in my class i defined a method to to execute a query in my database and returns result,
and i have a gridview control on my main form to show this result.
this is my code:
class:
public class CustomerClass
{
SqlConnection con = new SqlConnection("server=(local);database=Tailor;integrated security=true;");
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
public CustomerClass()
{
}
public object selectCustomers()
{
con.Open();
SqlCommand select = new SqlCommand("select * from Customers",con);
select.ExecuteNonQuery();
con.Close();
da.SelectCommand = select;
da.Fill(ds, "Customer");
return ds.Tables;
}
}
form load:
CustomerClass test=new CustomerClass();
object test2 = test.selectCustomers();
dataGridView1.DataSource = test2;
|
|
|
|
|
So, what is your problem?
|
|
|
|
|
Do a little more searching... there are plenty examples around this site, for example:
How to populate DataGridView, GridView with SQL statement in C#[^]
In general, use code similar to this in your method:
string strSQLconnection = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";
SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
SqlCommand sqlCommand = new SqlCommand("select * from mytable", sqlConnection);
sqlConnection.Open();
SqlDataReader reader = sqlCommand.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
|
|
|
|
|
See here[^] on how to connect to the database. The returned DataSet can be bound to a grid, which will show the results.
If you're working with SQL Server, you might want to have a look at LINQ to SQL.
|
|
|
|
|
I am stuck with regular expressions. In fact, I want the 'T' to be optional, and I got a working example:
string text = "123T234";
Regex regex = new Regex(@"([0-9]{3})[T]?([0-9]{3})");
Match stuff = regex.Match(text);
Now, why doesn't
Quote: ([0-9]{4})-([1-9]|[1][0-2])-([0-2]?[0-9]|[3][0-1])[T]?([0-1]?[0-9]|[2][0-3])[:]([0-5]?[0-9])[:]([0-5]?[0-9])?.?([0-9]{1,6})[Z]?([+-]?[0-9][\.|,]?[0-9]?|[0-9]{2}?|[+-]?[0][1][0-2][\.]?[0-9]?|[0-9]{2}?)
produce a match for
2014-02-01T14:12:33Z+1
?
Any help is greatly appreciated.
[Solved by Original Griff]
Clean-up crew needed, grammar spill... - Nagy Vilmos
modified 6-Feb-14 5:45am.
|
|
|
|
|
Because the Month group explicitly excludes it:
([0-9]{4})-([1-9]|[1][0-2])
Try:
([0-9]{4})-(0?[1-9]|[1][0-2])
BTW: [0-9] is equivalent to \d which is a little shorter!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I don't want the T to be included in any group - Wouldn't
OriginalGriff wrote: (0?[1-9]|[1][0-2])
allow months to be 0?
Maybe I am just slow, but I don't get why the solution should allow the 'T' to be missing?
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
No, because it is an optional '0' followed by a non-zero digit, or a '1' followed by a '0', '1', or '2'.
'0' on it's own isn't allowed, nor is "00"
The '?' after the 'T' specifies "zero or one" instances, so it works with or without it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|