|
Help me out with this error please.
StreamReader input = new StreamReader("C:\Program Files\Prefs\num.txt");
Invaild escape sequence.
Problem, and answer please. Thanks for the help.
|
|
|
|
|
The \ character is escape character in C# strings. To put a \ character in a string you have to escape it, that is using \\.
Or you can put @ before the string, then it does not process escape sequences.
---
b { font-weight: normal; }
|
|
|
|
|
Ok thanks that helps, but how do i make it look on the clients pc for the file?
Thanks again.
|
|
|
|
|
You don't.
Unless you run a component or applet in the browser, so that the user can accept it, there is no way you can get any information at all about the client's file system.
---
b { font-weight: normal; }
|
|
|
|
|
if you have sufficient rights to the clients pc, and the file is on a shared directory, you could use a UNC path: \\ComputerName\Sharename\....\filename.ext
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
You should do
StreamReader input = new StreamReader("C:\\Program Files\\Prefs\\num.txt");
or
StreamReader input = new StreamReader(@"C:\Program Files\Prefs\num.txt");
|
|
|
|
|
I'm trying to open a user with insert SQL query to Access. This is the statements:
string sqlCreateNewUser = "INSERT INTO usersTbl ( UserName, Password) " +
"VALUES (" + username.UserName+ ", " + username.Password + ")";
Think the eror derived from the class I wrote to user. This is the class:
public class user
{
private string username;
private long password;
public user(string username, long password)
{
this.username = username;
this.password = password;
}
///
/// Gets, Sets username.
///
public string UserName
{
get
{
return this.username;
}
set
{
this.username = value;
}
}
///
/// Gets password.
///
public long Password
{
get
{
return this.password;
}
set
{
this.password = value;
}
}
}
Please help me find the false.
BTW: sorry I don’t use indentation. Just couldn’t understand the tags system here...
Where would I find some info on it?
TIA,
Ronen
|
|
|
|
|
Standard question #2:
What error message do you get?
---
b { font-weight: normal; }
|
|
|
|
|
The Error I get is:
"Syntax error in INSERT INTO statement"
Tried it with the extra quotes, with no use.
I would rather do it this way at this stage. I think the syntax is OK (?)
What do you think of the user class I wrote?
|
|
|
|
|
Username or password might be reserved words, depending on what connection you use. Put brackets around them: [username], [password]
---
b { font-weight: normal; }
|
|
|
|
|
The problem was with Password as a reserved word. once put it brackets around it- solved.
cheers!
Ronen
|
|
|
|
|
You need to enclose your values in single quotes:
... "VALUES ('" + username.UserName+ "','" + username.Password + "')";
note the extra single quotes I have added.
A better way to do this would be to use parameters and a stored procedure (querydef in access lingo), then you wouldn't have to worry with things like the single quotes (which will need to be doubled up if they are part of a name - O'Neill - becomes O''Neill - in order to work). If you use a strored procedure with parameters, you won't have to worry about escaping the embedded single quote.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
Hi, how can I edit an windows control property with other threading tha the current works in the form?
I make a threat to do some tasks, and I want to show to the user the progress in a progress bar and subtask it is doing in label.
I try but throw me an exception because the threadin to edit controls property is other than the one is doing my custom tasks.
than you!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
You can't access a control directly from a thread different than the one that created the control you need to use Invoke or BeginInvoke to do this. See this article[^] for more details.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
Hi..
I have a datagrid and an EditCommand
Now, when I click the UpdateCommand- link button...
private void dgProjects_ItemUpdate(object sender,DataGridCommandEventArgs e )
{
string ProjectId = e.Item.Cells[0].Text
....
}
It should return me the first column value in the clicked row???
But its not...
Is something wrong.. or some other way...???
Thanks
|
|
|
|
|
The answer is a little more complicated than it should be....Or at least I thought it should be.
The following code is meant to take the value of the cell (that the user has selected and changed)and write this value into the database. It then refreshes the DataGrid to show the new value.
The hardest part to understand is that you have to create a DataGridTableStyle object to do this. The reason for creating this object is that the class provides the necessary methods and properties that you need to access.
<br />
private void updateButton_Click(object sender, System.EventArgs e)<br />
{<br />
DataGridTableStyle ts1 = new DataGridTableStyle();<br />
<br />
DataGridCell myCell;<br />
myCell = UserdataGrid.CurrentCell;<br />
<br />
ts1.MappingName = "SessionTable";<br />
<br />
UserdataGrid.TableStyles.Add(ts1);<br />
<br />
string infoStr = null;<br />
int j = 0;<br />
<br />
foreach(DataGridTableStyle gridStyle in UserdataGrid.TableStyles)<br />
{<br />
<br />
foreach(DataGridColumnStyle colStyle in gridStyle.GridColumnStyles)<br />
{<br />
if (j == myCell.ColumnNumber)<br />
{<br />
infoStr = colStyle.MappingName;<br />
}<br />
j++;<br />
}<br />
}<br />
<br />
int i = UserdataGrid.CurrentRowIndex;<br />
<br />
String userId = UserdataGrid[i, 7].ToString();<br />
<br />
sql.UpdateRecord("SessionTable", infoStr, "UserId", userId, UserdataGrid[myCell].ToString());<br />
<br />
FillData();<br />
UserdataGrid.SetDataBinding(dataSet, "SessionTable");<br />
UserdataGrid.Refresh();<br />
}<br />
<br />
Whoooo!!! It sure seems like alot of work just to get a value, change it and then display the changes. But there are some positive things to note:
1) This is the entire implementation(minus the sql statements for the database and the implementation of FillData())
2) I did not have to use EditCommand
3) Though not the most elegent solution, it works!
Well, I hope this helps. I know what it's like to wonder why something isn't working when it looks like it should. Sometimes we need to look outside of the "logical box" to make it work.............
Have a good one,
Snowblind37 aliasing as CodeBlind37 these days.
|
|
|
|
|
How come I cant define the List type using the statement:
List<int> intList = new List<int>();
it seems it does not recognize the List definition.
Thank you.
|
|
|
|
|
Did you wrote a using directive for the correct namespace, so the use of types in that namespace is allowed without having to specify the namespace.?
www.troschuetz.de
|
|
|
|
|
The only directive that I think I need is System.Collections;
And that is what I have.
Do I need some other directives to use List
Thank you
|
|
|
|
|
The System.Collections namespace doesn't contain a List type. There are ArrayList or SortedList type and IList interface.
www.troschuetz.de
|
|
|
|
|
There is no List definition in C#. I suggest you go to http://msdn.microsoft.com/ . There you will be able to find the definitions of all the classes available. They are mostly the same for C# and VB, etc. Actual class names will differ from Java but the functionality will be more or less the same.
CodeBlind37
|
|
|
|
|
Hi,
I've got a program that reads field names and values from a database table and searches Xml documents for them. I find them in the Xml file using XPath XPathNavigator and the XPathNodeIterator objects. However, I can't find a method that replaces a node value once I find it, I've looked through other classes such as XmlWrite, XmlNode, etc but I can't find anything suitable.
There must be something in .NET that repalces a node(tag) value in Xml according to the node structure??
|
|
|
|
|
Hello,
I'm trying to close a MDI child (by calling this.Close() ) is trying in the Validated event handler for one of its controls, but it refuses to close.
I've checked the OnClosing handler, and when called, e.Cancel is always true. I tried setting it to false , but then I get a NullReferenceException (not in my code, my debugger just pops up pointing at the last line of code in my Main ).
I could just hide it, but I would like it to be closed later, so it's not taking up memory unnecessarily.
It seems that when I try to close it, it's in some process that has to finish, and that's the reason of the NullReferenceException .
Could anyone shed some light?
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
A few things come to mind........
-What other signal flow might be trying to run? I would find this out before anything. Do you have an infinate loop going on somewhere? A reference to a method that is waiting for information?
- The NullReferenceException is likely because it hasn't reached the OnClosing handler
- Does the code even reach your this.Close(). Try printing out an "I'm here" before the Close and see if it is even getting that far
- Not a bad idea to print out statements all the way through the flow and see where it crashes
Hope that helps
CodeBlind37
|
|
|
|
|
I've solved it. I already had a timer firing every 1/4 of a second, so I just set a flag mustClose to true, and in the timer the form closes itself. And it works fine.
But I still have the doubt on why it didn't work.
Snowblind37 wrote:
What other signal flow might be trying to run? I would find this out before anything. Do you have an infinate loop going on somewhere? A reference to a method that is waiting for information?
No. Nothing else. Basically on the Validated event, if it finds a duplicate asks on how to proceed (in a modal form) and if user chooses to work on the duplicate, Close() is called before returning from the event handler.
Snowblind37 wrote:
The NullReferenceException is likely because it hasn't reached the OnClosing handler
It's after the OnClosing. I've verified it in the debugger, and the exception only happens if I set e.Cancel to false in the OnClosing handler (which misteriously is set to true .)
Snowblind37 wrote:
Does the code even reach your this.Close().
Yes, and from there it goes to the OnClosing handler, with e.Cancel set to true (it's not a base class where a derived class could set it before.)
Snowblind37 wrote:
Not a bad idea to print out statements all the way through the flow and see where it crashes
I've stepped through all my code in the debugger. The crash is only when I try to set e.Cancel = false in the OnClosing handler, and it occurs after my handler returns, somewhere in the middle of the framework code.
When I have some time, I'll try to reproduce it in a simpler program.
Thanks for your comments!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|