|
Hello Mav,
Thanks so much for your help.
I know that the SQL has a command :Create table
I mean how can i do this with Code dynamicaly i tried this code put it return error.
using System;<br />
using System.Data;<br />
using System.Data.OleDb;<br />
using System.IO;<br />
namespace FrameworkExamples<br />
{<br />
class SampleADONETExecSQLAccess<br />
{<br />
static void Main()<br />
{<br />
OleDbConnection db;<br />
OleDbCommand dbcmd;<br />
string connstring;<br />
int recsaffected;<br />
StringWriter sql;<br />
connstring = "Provider=Microsoft.Jet.OLEDB.4.0;";<br />
connstring += @"Data Source=C:\Documents and Settings\Administrator\Desktop\db1.mdb;";<br />
db = new OleDbConnection(connstring);<br />
db.Open();<br />
sql = new StringWriter();<br />
sql.WriteLine("create table tbl1");<br />
sql.WriteLine("(");<br />
sql.WriteLine("id int identity(1, 1) not null primary key,");<br />
sql.WriteLine("field1 varchar(255) null,");<br />
sql.WriteLine("field2 bit null");<br />
sql.WriteLine(")");<br />
sql.Flush();<br />
dbcmd = new OleDbCommand();<br />
dbcmd.CommandType=CommandType.Text;<br />
dbcmd.CommandTimeout=30;<br />
dbcmd.CommandText=sql.ToString();<br />
dbcmd.Connection=db;<br />
recsaffected = dbcmd.ExecuteNonQuery();<br />
db.Close();<br />
dbcmd = null;<br />
db = null;<br />
sql = null;<br />
}<br />
}<br />
}
|
|
|
|
|
Ouch!
Why on earth are you using a StringWriter to build your SQL query?
Could it be that you thought of the StringBuilder class? But even then, your create table statement can be packed in a single string and thus be much more readable.
And the OleDbCommand can be created with one line, not 5 like in your code: OleDbCommand dbcmd = new OleDbCommand(db, commandText);
You shouldn't set your objects to null at the end of your function, but rather call their Dispose() methods so that resources are freed before the objects are garbage collected. This should be done even in an error situation, so using a try/finally would be a good idea.
If you get an error, knowing what the error is is essential to fixing it. I guess you're getting an OleDbException telling you that there's a syntax error somewhere. I don't remember all the data types for Access, but I think the line id int identity(1, 1) isn't syntactically correct. IIRC, you'll have to use counter instead of int identity(1,1) .
Regards,
mav
|
|
|
|
|
Hey
I wonder if its posible to have multiple threads reading from one stream at the same time?
In this case i am opening a SerialPort, from this port there will be a big dataflow.
I then give other units(parts of the program) rights to read this stream, this have to be with no data loss.
Note: This is with Framework 2
Best regards
Jimmy
|
|
|
|
|
No, think about it. A stream is a sequence of bytes. To read different parts of the stream at the same time, you will need AsyncFileIO (look on MS Research), but your case is a SerialPort, and there is no way to read what is not there.
A better way would be the following:
In the main thread read the stream, and categorize the input. Then use a use a threadpool or threads the do the processing of the input. Again you can run into problems if you need the processing to finish sequentially.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
Okay!
This program will be a miner modul(Window control library). It will proved the rest of the program with all the information that is coming from the serial port.
Then we thought that if we provide a stream from the serial port to other parts of the main program thay maby could read from this at the same time?
If we under stand you right, the buffert will throw away the readed byte when the first reader have read it? and thereby there will not by any data left to read for the readers that comes after the first before?
Its inportant that the other units in this main program can read the same thing at the same time.
for example: The stream from serialport should be both displayed in ritchtextbox and saved at the same time. It will also be displayed with in other units(controls) in this main program at the same time.
|
|
|
|
|
Are you asking how you can get two completely different parts of your program to read the exact same data from the SerialPort?
You don't. You write a control that wraps the SerialPort "stream", ask you call it, and exposes an event that various parts of your program can subscribe to. When data comes in on the SerialPort, your control then checks to see if there are any subscribers, then fires off the event with the data that came in on the port. It's called Multicasting and you can read about it here[^] on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have tried to open a text file, read it line by line, and write it to second text file...everything smooth as poetry. But then the shock! The output file is writen in UNICODE - 2 bytes per character,but I would realy,realy like to get the SteamWriter to write in old-school 1 byte per character mode. Is there any possibilityes other then reading the text binary?
|
|
|
|
|
|
HI
I write a program that prapare a report for printing but now i want to save and convert it to MSword ( for some reasons i can't use crystal report )
is there a simle way to convert the print to word or text file ?
Please help me
Regards' Amir jalaly
|
|
|
|
|
Have you tried using Word Automation ?
|
|
|
|
|
Hi
thanks for your help . but can help me more ? what's word Automation ?
thanks a lot . Amir Jalaly
|
|
|
|
|
Try searching the web or this forum for Word Automation....you'll find tons or sample code
|
|
|
|
|
hallo i need information about virus over network layer
if you have pdf file or any internet site that may help me
please do that.
thaaaaaaaaaaaaank for all.
|
|
|
|
|
|
He wants to know how to write a virus in c# that distributes itself in C#!!!!
Its simple.
POLICE!!!!!
|
|
|
|
|
|
One can disassemble the code of an assembly (in say Visual C# language) complied by using Visual Studio .NET even if it is a Release build. This can be done by using the disassembler "ILDASM.EXE" provided with the VS .NET . It shows all details of the code giving vivid details of all methods, properties, fields, classes, structs, etc. What then is the security of a complied assembly which is in the MSIL version? Tomorrow, anybody can copy your idea and may be even replace some portions of the compiled file, such as the code security portions. Can anyone explain as to whether there is some way out to ensure that a particular assembly could not be disassembled using the aforesaid disassembler or some other similar utility. (here I may point out that an assembly converted to native code by using ngen.exe is only a partial solution in as much as the resultant file cannot be stored in the application directory but is stored in the protected catche). Any solutions or comments?
|
|
|
|
|
You cant prevent disassembly, but you can make reassembly very hard. You can use an obfuscator (but thats really just designed to keep the idiots away), release (iow optimized) builds help too. Have only the least accesible modifiers on classes and members. Another is to make sure you sign all assemblies. If you place your 'security' code in a signed assembly that all your other assemblies depends on, ALL assemblies would have to be altered (resigned) to reconstruct the program. At this point most people says "stuff it" :p
With all that said, I have only seen 1 (one) .NET program that didnt seem 'crackable'. I will not give you details.
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
|
|
|
|
|
Hi
Im currently creating a login form and i want to check if the input user name and password matches the data in the database. I have created a table called Users in my database, that contains two columns user name and password. I have declared my sql command text to the sql string and filled my dataset. I then created if else statement such as:
if(username_txt.Text == loginDS1.login.UserNameColumn.ToString() && password_txt.Text == loginDS1.login.PasswordColumn.ToString()
{
main_frm main_frm = new main_frm();
main_frm.Show();
}
else
MessageBox.Show("Incorrect username and password!");
Im a new starter and i really dont know the correct technics however i really need want to learn..... Help!!!
|
|
|
|
|
A few things to consider...
Make sure to use a parameterized query (preferably a stored proc) instead of just a plain query string. I.e.
cmd.CommandText = "usp_GetUserInformation";
cmd.Parameters.Add("@userName", userName); //from username_txt.Text
instead of ...
cmd.CommandText = "select UserName, Password from Users where UserName = '" + username_txt.Text + "'";
The reason for this is to prevent SQL injection attacks.
Another thing...
Don't store the password in plain text in the database. When the user sets up the password, hash it and store the hash. Then when checking the password, hash what they enter the same way and compare it to what is in the db.
Jeff Martin
My Blog
|
|
|
|
|
Hi all,
I need to read the system time and write it to text file when ever the user presses some alphabet keys.
thanks for anykind of help,
Pavan.
Suman
|
|
|
|
|
|
Hi,
thanks for ur reply... if u dont mind can u give me a precise command... i need to read the time upto milliseconds... like hh:mm:ss:ms.... i saw tht tickcounts will do tht but i didnt understand how to use it.
Can u please help me out on this....
Thanks in advance,
Pavan
|
|
|
|
|
how about this.
DateTime[^]
FileStream[^]
You have to start by reading the docs, right?
There are code examples and useful links in both the above docs, if and when you get stuck on a particular part please post again.
|
|
|
|
|
thanks for ur links, i do have gone through them. But i didnt get how to read the time upto NANO or MILLI seconds at the particular instance when we press a specified key on the keyboard, which is the only problem i am having.
I want the format to be like... hh:mm:ss:ms (where ms is milliseconds)
The millisecond property is not related to the system time while it is related to the instance of the application.
it would be greatful if anyone can help me on tht.
thanks,
Suman
|
|
|
|