|
Thanks fort heloping me. I am using access database. Do I have to change Sql to Ole in the code you wrote me? For Example:
cmd1.CommandText = "INSERT INTO WIRETBL(Code, Street, Alley, Date, Time) VALUES(@Code, @Street, @Alley, @Date, @Time)";cmd1.Parameters.Add("@Code", OleDbType.Int).Value = x1;cmd1.Parameters.Add("@Street", OleDbType.Varchar).Value = x2;cmd1.Parameters.Add("@Alley", OleDbType.Varchar).Value = x3;cmd1.Parameters.Add("@Date", OleDbType.DateTime).Value = x4;cmd1.Parameters.Add("@Time", OleDbType.DateTime).Value = x5;cmd1.ExecuteNonQuery();
Sourie
|
|
|
|
|
Yes you have to.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Unfortunately I got Syntax Error
Sourie
|
|
|
|
|
What error message you get?
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
"String was not recognized as a valid DateTime." for this line:
DateTime x4 = System.Convert.ToDateTime(textBox4.Text);//Date
Then I changed DateTime to String:For example for this line:
String x5 = System.Convert.ToString(textBox5.Text);//
cmd1.Parameters.AddWithValue("@Time", OleDbType.VarChar).Value = x5;
but this time I got this error:
Syntax error in INSERT INTO statement.
Sourie
|
|
|
|
|
DateTime.ParseExact(textBox4.Text,"MM/dd/yyyy",System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat)
Sourie wrote: Syntax error in INSERT INTO statement.
Show here how do you make insert command.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
con1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=F:\WireDb.mdb";
con1.Open();
Int32 x1 = System.Convert.ToInt32(textBox1.Text);//Code
String x2 = textBox2.Text;//Street
String x3 = textBox3.Text;//Alley
DateTime x4 = System.Convert.ToDateTime(textBox4.Text);//Date
DateTime x5 = System.Convert.ToDateTime(textBox5.Text);//Time
cmd1.CommandText = "INSERT INTO WIRETBL(Code, Street, Alley, Date, Time) VALUES(@Code, @Street, @Alley, @Date, @Time)";
cmd1.Parameters.AddWithValue("@Code", OleDbType.Integer).Value = x1;
cmd1.Parameters.AddWithValue("@Street", OleDbType.VarChar).Value = x2;
cmd1.Parameters.AddWithValue("@Alley", OleDbType.VarChar).Value = x3;
cmd1.Parameters.AddWithValue("@Date", OleDbType.DBDate).Value = x4;
cmd1.Parameters.AddWithValue("@Time", OleDbType.DBTime).Value = x5;
//cmd1.ExecuteNonQuery();
cmd1.CommandType = CommandType.Text;
cmd1.Connection = con1;
cmd1.ExecuteNonQuery();
adp1.SelectCommand = cmd1;
DataTable tb1 = new DataTable();
adp1.Fill(tb1);
dataGridView1.DataSource = tb1;
con1.Close();
Dear Friend how can I learn working with Access Database in c#?
I need a complete reference to not bother you alot.
Sourie
|
|
|
|
|
you can read this link[^]
hope it helps
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
Oh thanks alot it is a good start for me.I have to read it and test ur program myself.
But another question, How I can use a datagridview to show a table's content without puting datagridview object on the form? I want to define datagridview in my code.
Sourie
|
|
|
|
|
1. create DataGridView instance
2. Set it datasource to your DataTable or DataSet
3. if you need to show the grid just add it to container control like form or panel with method "containerControl to add".Controls.Add("your datagridview") ie.
form1.Controls.Add(myGrid);
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
Wow, Finally I wrote a program .
Now I know what's the exact meaning of adapter, connection, dataset, datatable, and command.
I will try your suggestion to use datagridview also.
Sourie
|
|
|
|
|
Bravo!
It worked also. thanks alotttttttttttttt. I won't forget your kind.
may I get your help regard working with ports (Serial and USB) in c#?
Sourie
|
|
|
|
|
just follow this link[^]
there are many results here that you maybe want to know.
hope it helps
|
|
|
|
|
Hello again, according the lessons you gave me, I wrote a program that shows content of a table in a datagridview.
Now I want to sort the content of the table based a field(ASC or DEC) and show the result in that datagridview.
Database name= WirdDb, tablename= tbl2, fields: No, Code, Street, Alley, Status, Date and Time.
I want to sort the content of tbl2 according field "Street" ascendingly.
Would you please help me.
OleDbDataAdapter adapter2 = new OleDbDataAdapter();
OleDbCommand command2 = new OleDbCommand("SELECT * from tbl2"+tbl2.Street, conn);
adapter2.SelectCommand = command2;
OleDbCommandBuilder cb2 = new OleDbCommandBuilder(adapter2);
DataSet ds2 = new DataSet();
adapter2.Fill(ds2, "tbl2");
DataTable dt2 = ds2.Tables[0];
DataGridView dgv2 = new DataGridView();
dgv2.DataSource = dt2;
this.Controls.Add(dgv2);
Sourie
|
|
|
|
|
hi all,
I m a student, currently having problem on how i can start programming.
my project require the use of an measurement device and it measurement are taken from the usb port and save in notepad .txt format, i am suppose to come out with an real time graphical display of the measurement, but i have no idea how i could start on it as i am new in programming. any help or suggest would be greater appreciated. Thanks
|
|
|
|
|
You should have a library to communicate with your measurement instrument. Probably you can download it from the manufacturers web-site.
How to display the measurements on a graphical display? ZedGraph : http://www.codeproject.com/KB/graphics/zedgraph.aspx[^]
Don't bother with other plotting libraries, ZedGraph is the best.
Good luck
zafer
|
|
|
|
|
How can I set the tooltip location?
Right now I am setting a big enough tooltip size and then drawing it at desired location. Following is the code I have written.
private void Form1_Load(object sender, EventArgs e) {
ToolTip oTooltip = new ToolTip();
oTooltip.OwnerDraw = true;
oTooltip.Draw += new DrawToolTipEventHandler(oTooltip_Draw);
oTooltip.Popup += new PopupEventHandler(oTooltip_Popup);
oTooltip.SetToolTip(this.button1, "text");
}
void oTooltip_Popup(object sender, PopupEventArgs e) {
e.ToolTipSize = this.Size;
}
void oTooltip_Draw(object sender, DrawToolTipEventArgs e) {
Graphics oGx = e.Graphics;
oGx.Clear(this.BackColor);
oGx.DrawEllipse(Pens.Black, 20, 20, 20, 20);
oGx.DrawString("text",this.button1.Font,Brushes.Blue,20,20);
}
Somehow I am not too confident about this approach. Is there a better way to achieve this?
"If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry
|
|
|
|
|
Use ToolTip and try these :
private void button_MouseLeave(object sender, EventArgs e)
{
toolTip1.Hide(this.button);
}
private void button_MouseMove(object sender, MouseEventArgs e)
{
toolTip1.Show("some text", this.button, e.X + 10, e.Y + 10);
}
|
|
|
|
|
Wasn't aware that .Show for a tooltip accepted a location. Thanks!
- Matthew (@CSharpByDesign)
|
|
|
|
|
Hello,
I've made a chat program, inspired by the WPF/WCF chat tutorial here.
The program is complete, and works well, but when I give it to other friends it doesn't work. I'm hoping that by explaining the simptoms someone could help me:
1) For 2 people, the program won't even load, it will show an error "0xc0000135". Maybe .Net framework 3.5 is not installed? Can I check that before loading?
2) For one guy, the program manages to catch the exception, saying "Object reference not set to an instance of an object", on the following lines of code:
TcpClient connection = new TcpClient();
ChatRoom chat = new ChatRoom(connection, boxName.Text);
chat.Show();
this.Close();
Meaning I didn't initialize "connection", but I just did!
3) For another guy, the program terminates also after these 3 lines, but without managing to catch the exception, saying the program had to close.
4) For someone else, the program first shows the ChatRoom window, and then shuts down. I've put everything I could in a try/catch block and it doesn't help.
What bothers me is that I get none of these problems.
Thanks!
|
|
|
|
|
either new TcpClient is failing or new ChatRoom(connection, boxName.Text) is failing
try this:
try
{
TcpClient connection = new TcpClient();
ChatRoom chat = new ChatRoom(connection,boxName.Text);
chat.Show();
this.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
and see what it says on your friends' machines
|
|
|
|
|
Thanks for the reply.
That's what I already did, and he's getting "Object reference not set to an instance of an object", I'm sure that it's failing right before the new Chatroom. I've also added try/catch blocks in the constructor, but it's not even getting there.
Why should it fail for all of my friends, but not for me or my laptop? It's not even connecting yet to the server, just initializing. I've made my friends install .Net framework 3.5 SP1 and it's no help.
It's really disappointing as I was hoping to continue learning WPF...
Thanks again
|
|
|
|
|
Well I think the best way to diagnose the problem would be to take you and your code over to one of your freinds machines, put in a breakpoint at the start of these lines, and step through the code. You will then know exactly what crashes the program, and you can then inspect the object using the debugger.
Hopefully this would shed some more light on the problem, and then you could create a solution.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Thanks for the reply.
As I was sure that it's the "new TCPClient" failing to initialize (though it wasn't kind enough to actually throw an exception), I changed TCPClient to Socket and configured it to work with TCP. Now it works for my friends.
But still I have one friend, who has .Net Framework 3.5, and when he tries to open my program, it crashes. No exception, no nothing. ("ChatClient.exe has stopped working").
This is frustrating, not only that with WPF I have to convince my friends to stop working on their PCs for 30 minutes so .Net framework would install, but my prefectly good program doesn't work on some PCs. So much for the .Net compability...
Thanks.
|
|
|
|
|
What is persistent object and transient object in OOP? Could you give an example in C#?
Best regards...
|
|
|
|
|