|
|
captjack wrote: I read somewhere that the buffers might need to get flushed/reset, but can't seem to find that method.
Where did you look? Everywhere but in the StreamWriter class?
You have to use the Flush method of the StreamWriter before you move the position in the underlying stream, otherwise it may write whatever is in the buffer to the new position:
using (FileStream fs = new FileStream("c:\\textFile.txt", FileMode.Open, FileAccess.ReadWrite)) {
using(StreamWriter sw = new StreamWriter(fs)) {
sw.BaseStream.Seek(10, SeekOrigin.Begin);
sw.Write("0005");
sw.Flush();
sw.BaseStream.Seek(1, SeekOrigin.Begin);
sw.Write("Test");
}
}
Setting auto-flush (as suggested elsewhere in the thread) works, but if you use it when writing more than a few strings to a file you can reduce the performance, as a whole cluster (about 8 kiB) is written to the disk each time.
Also, you have to be very careful when changing the position to write in a text file. Characters outside the ASCII character set use more than a single byte in the file, so you can easily corrupt characters in the file by overwriting part of a multi-byte character. Be careful only to write single-byte characters and only overwrite single-byte characters.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Good Afternoon All
i think its Firday fever, am tired. I think this Happens sometimes. let me get to the Problem. Am doing an OleDb Project
I have an Access DB and the table is Users , here are the Field and dataType
ID = Autonumber(int)
Firstname = TEXT
LastName = TEXT
Username = TEXT
Password = TEXT
Email = TEXT
Now i have a Function that inserts into these Field from my DAL that is Written like this
public int Register_User(String Firstname, String LastName, String Username, String Password, String Email)
{
int Res=0;
con = new OleDbConnection(strcon);
cmdinsert = new OleDbCommand();
cmdinsert.CommandText = "insert into Users Values(?,?,?,?,?)";
cmdinsert.CommandTimeout = 0;
cmdinsert.CommandType = CommandType.Text;
cmdinsert.Connection = con;
cmdinsert.Parameters.Add("Username", OleDbType.VarChar,30).Value = Convert.ToString(Username);
cmdinsert.Parameters.Add("Password", OleDbType.VarChar,30).Value = Convert.ToString(Password);
cmdinsert.Parameters.Add("Firstname", OleDbType.VarChar,30).Value = Convert.ToString(Firstname);
cmdinsert.Parameters.Add("LastName", OleDbType.VarChar,30).Value = Convert.ToString(LastName);
cmdinsert.Parameters.Add("Email", OleDbType.VarChar, 30).Value = Convert.ToString(Email);
try
{
con.Open();
Res =(int) cmdinsert.ExecuteScalar();
}
catch (OleDbException)
{
throw;
}
finally
{
con.Close();
}
return Res;
}
When i try to insert , i get an Exception.
Number of query values and destination fields are not the same.
Can you please Point the Problem for me
Thank you
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
try changing your query to
"INSERT INTO Users(Firstname,LastName,Username,Password,Email) VALUES(?,?,?,?,?)"
|
|
|
|
|
is there any reason you are doing a
Convert.ToString(Username)
to set the value, as it is being passed in as a string anyway?
|
|
|
|
|
Just to make sure? Or bloat it?
Chuck Norris has the greatest Poker-Face of all time. He won the 1983 World Series of Poker, despite holding only a Joker, a Get out of Jail Free Monopoloy card, a 2 of clubs, 7 of spades and a green #4 card from the game UNO. In the movie "The Matrix", Chuck Norris is the Matrix. If you pay close attention in the green "falling code" scenes, you can make out the faint texture of his beard. Chuck Norris actually owns IBM. It was an extremely hostile takeover.
|
|
|
|
|
Am the Day have been long, and you get Small Error like missing semicolon
this happens "Fool Proof it".
Thanks for you Comment
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
FoolProffing it i geuse after a long day when the code gives me an Error that is Simple to solve, but because i cant see it because of the tired mind , i will try to make sure that i fool proof every possibility
Thanks for your Comment
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
hi Man
Am back with fresh mind. The Problem was the Order of Parameters and your insert statement helped.
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
I don't use Access, but I suspect you need to list your fields so it knows to skip the id
cmdinsert.CommandText = "insert into Users(Firstname,LastName,Username,Password,Email) Values(?,?,?,?,?)";
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hallo Vuyiswa
Please look at the soluction below I have tested it and it works.
public int Register_User(String Firstname,String LastName,String Username,String Password,String Email)
{
int Res = 0 ;
OleDbCommand cmdinserts;
cmdinserts = new OleDbCommand();
con = new OleDbConnection(strcon);
cmdinserts.CommandText = "insert into [Users]([Firstname],[LastName],[Username],[Password],[Email]) Values(?,?,?,?,?)";
cmdinserts.CommandTimeout = 0;
cmdinserts.CommandType = CommandType.Text;
cmdinserts.Parameters.Add("@Firstname",OleDbType.Char,30).Value = Firstname;
cmdinserts.Parameters.Add("@LastName",OleDbType.Char,30).Value = LastName;
cmdinserts.Parameters.Add("@Username",OleDbType.Char,30).Value = Username;
cmdinserts.Parameters.Add("@Password",OleDbType.Char,30).Value = Password;
cmdinserts.Parameters.Add("@Email",OleDbType.Char,30).Value = Email;
cmdinserts.Connection = con;
try
{
con.Open();
//Res = (int)cmdinsert.ExecuteScalar();
Res = (int)cmdinserts.ExecuteNonQuery();
}
catch (OleDbException)
{
throw;
}
finally
{
con.Close();
}
return Res;
}
Hope this helps.
Ngiyabonga
Langa
|
|
|
|
|
Wow Langa,
Thanks Am Proud of you, i just came back now and Fresh again, I see that the Order of Paramaters was the Problem. They should be the Same.
Thanks
I gave you 5
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hi,
What is best machinsm to check whether the server is UP or not?
How far ping mechanism is reliable?
If any good machanism is there to check whether server is UP or not?
Kindly help me
|
|
|
|
|
Don't cross post, geeze.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
balu12345 wrote: What is best machinsm to check whether the server is UP or not?
I would not recommend the C# mechanism.
|
|
|
|
|
Hello all!
A silly question concerning the OSVersion. When I call the following method it returns the platform as the following;
"Microsoft Windows NT 5.1.2600 Service Pack 2"
Despite under the control panel it is listed as;
"Microsoft Windows XP Professional Version 2002 Service Pack 2"
Is there anything that maps one from the other?
Many thanks!
|
|
|
|
|
|
|
Hi,
My scenario is as follows..,
1.On the User PC, an user will give click on a button then It will take a value to the server and update it to a file ......
2.then from server it will get the updated file to User PC and then it will invoke an exe in that user PC ..........
3.then up on entering some values again from client some values will be sent to server.
Here User PC and Server are in WAN
Iam Unable to get the proper Idea to solve this.....
What is the best machanishm to solve this?
How to solve the above Problem?
Kindly Guide me
|
|
|
|
|
www.rentacoder.com
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Yep. Maybe he can get someone to do a lousy project for 10 bucks
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi,
I need to some Idea or help to start but not some one to do my job.
Iam not a lasy person to give my work to some one...
I just need some initial Idea to start.....
ok ..byee...
|
|
|
|
|
Using this code to pull data tables to populate two datagrids yet when it calls the select query
I get just the first letter of the table.
The code that is commented out with the //places the dbo.Table in the dropdown combo box but error because the select query will fire with dbo.table.
private void EnumerateTables(ComboBox cmb, String databaseName, bool isAccess)
{
if (!isAccess)
{
var srv = new Server(Properties.Settings.Default.ServerInstance);
srv.Databases.Refresh();
foreach (Database db in srv.Databases)
{
if (db.Name == cmbboxSqlDb.Text)
{
BindingSource bs = new BindingSource();
bs.DataSource = db.Tables;
bs.DataMember = "Name";
cmb.DataSource = bs;
}
}
}
else
{
if (AccessConnString != null)
{
var conn = new OleDbConnection(AccessConnString);
conn.Open();
var schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" });
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
cmb.Items.Add(schemaTable.Rows[i].ItemArray[2].ToString());
}
}
}
}
Learning to Code
|
|
|
|
|
Hi!
I am working on a desktop application in C#. I'd like to show a small icon whether the user has still access to the database or not. Therefore I try to open a connection periodically (timer tick event every 10 sec). When I tested this application something strange happened
1) sql service not running -> I started application -> con.open fails -> catch block -> show disconnect icon
2) i started sql service -> con.open works -> show connect icon
3) i stopped sql service -> con.open STILL works??? -> no exception????
Below you can see my code.
Thread t = new Thread(delegate()
{
SqlConnection con = null;
try
{
string conStr = "CONNECTIONSTRING GOES HERE";
con = new SqlConnection(conStr);
con.Open();
datenbankStatus(true);
}
catch (Exception ex)
{
datenbankStatus(false);
}
finally
{
if (con != null && con.State == System.Data.ConnectionState.Open) con.Close();
}
});
t.IsBackground = true;
t.Start();
Any help would be great!!
Thx in advance
|
|
|
|
|
I have an india map(single image).In that map if i click on Andhra pradesh it should show that Andhra Pradesh Map. please help me for this work. i want this application in c# windows application.
|
|
|
|
|