|
somewhat OT, but, I have always found this behavior of PadLeft weird: Quote: A new string that is equivalent to this instance, but right-aligned and padded on the left with as many spaces as needed to create a length of totalWidth. However, if totalWidth is less than the length of this instance, the method returns a reference to the existing instance. If totalWidth is equal to the length of this instance, the method returns a new string that is identical to this instance.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
You do have to wonder what the SQL Server designers were smoking when they came up with that, yes ...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
anilkolla wrote: If we see the above example some columns are left aligned and some are right aligned we have to maintain the same format for the given list of strings. That's not random on a column. Text is aligned different from numbers. All you need to do to set the correct alignment is determine whether it is a text or a number.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I assume that the source of the data example shown is some form of structured tabular data. The misalignment in your example is proof of the difficulties involved.
Think about the issues in producing strings whose formats match/mirror the tabular data:
1. font: mono-spaced (simpler) vs. variable width (much more complex)
2. the variation in the length of entries for fields: you will have to do some form of analysis of all the data to figure our for each field the maximum space required.
What is your final goal here ? Print, or screen ? If screen, why not use a UI element designed for tabular data ?
Definitely review the content here to find some possibly useful code tools and resources: [^]. And, note that C# 6 has some new string interpolation features:[^]
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\hesham\Desktop\Database2.accdb");
OleDbDataAdapter da;
DataTable dt = new DataTable();
OleDbCommand cmnd;
public Form1()
{
InitializeComponent();
filldatagridview();
}
void filldatagridview()
{
dt.Clear();
da = new OleDbDataAdapter("Select * From Table1 ", cn);
da.Fill(dt);
dataGridView1.DataSource = dt;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
cmnd = new OleDbCommand("insert into Table1 values('" + textBox4.Text + "','" + textBox3.Text + "'," + Convert.ToInt32(textBox1.Text) + ",'" + textBox2.Text + "')", cn);
cn.Open();
cmnd.ExecuteNonQuery();
cn.Close();
filldatagridview();
MessageBox.Show("added success ", "add", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
textBox4.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
textBox3.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBox1.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
textBox2.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
cmnd = new OleDbCommand("Update Table1 Set name ='" + textBox3.Text + "',age = '" + Convert.ToInt32(textBox1.Text) + "', address='" + textBox2.Text + "'Where id='" + textBox4.Text + "", cn);
cn.Open();
cmnd.ExecuteNonQuery();
cn.Close();
filldatagridview();
MessageBox.Show("edit success ", "edit", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button3_Click(object sender, EventArgs e)
{
cmnd = new OleDbCommand("Delete From Table1 Where id='" + textBox4.Text + "", cn);
cn.Open();
cmnd.ExecuteNonQuery();
cn.Close();
filldatagridview();
MessageBox.Show("delete success ", "delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button4_Click(object sender, EventArgs e)
{
Close();
}
}
}
|
|
|
|
|
OK, now you're going to have to explain what you mean by "it doesn't work". That's not a valid problem description.
What DOES happen? What error messages do you get?
In a quick glance, how you're building your SQL INSERT statement is horrible and prone to many problems and even destruction of your entire database. Google for "SQL Injection Attack" for why it's so bad, and then Google for "C# SQL Parameterized queries" for discussions and examples of how to do it correctly.
|
|
|
|
|
Hi,
I'm guessing here, I think your filldatagridview() method only works well once; when you execute it again, it assigns the same DataTable object (possibly with a different content, but that is irrelevant here) as the DataSource to your DGV, hence the DGV doesn't know something should change.
Try adding
dataGridView1.DataSource = null;
before setting
dataGridView1.DataSource = dt;
|
|
|
|
|
Member 14366610 wrote: '" + textBox4.Text + "" Quotes don't match. Learn about parameterized queries.
Also, don't keep connections open outside their method. Also, there's a factory-method on the connection to create commands. They're all disposables, so they should all be in a using-clause.
Start over.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\hesham\Desktop\Database2.accdb");
OleDbDataAdapter da;
DataTable dt = new DataTable();
OleDbCommand cmnd;
public Form1()
{
InitializeComponent();
filldatagridview();
}
void filldatagridview()
{
dt.Clear();
da = new OleDbDataAdapter("Select * From Table1 ", cn);
da.Fill(dt);
dataGridView1.DataSource = dt;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
cmnd = new OleDbCommand("insert into Table1 values('" + textBox4.Text + "','" + textBox3.Text + "'," + Convert.ToInt32(textBox1.Text) + ",'" + textBox2.Text + "')", cn);
cn.Open();
cmnd.ExecuteNonQuery();
cn.Close();
filldatagridview();
MessageBox.Show("added success ", "add", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
textBox4.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
textBox3.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBox1.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
textBox2.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
cmnd = new OleDbCommand("Update Table1 Set name ='" + textBox3.Text + "',age = '" + Convert.ToInt32(textBox1.Text) + "', address='" + textBox2.Text + "'Where id='" + textBox4.Text + "", cn);
cn.Open();
cmnd.ExecuteNonQuery();
cn.Close();
filldatagridview();
MessageBox.Show("edit success ", "edit", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button3_Click(object sender, EventArgs e)
{
cmnd = new OleDbCommand("Delete From Table1 Where id='" + textBox4.Text + "", cn);
cn.Open();
cmnd.ExecuteNonQuery();
cn.Close();
filldatagridview();
MessageBox.Show("delete success ", "delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button4_Click(object sender, EventArgs e)
{
Close();
}
}
}
|
|
|
|
|
Could some .... what?
You haven't asked a question or described a problem. Just posting a code dump doesn't do that.
|
|
|
|
|
Hello Gentlemen,
Could somebody give a good advise for the following :
I am an aspirant in learning c# and I wish to make a GUI that can read canbus J1939 engine data to read RPM .
I could read the can-bus data by tapping to the vessels engine can bus using a can to USB converter called kvaserCAN. I do understand the PGN data frames for the bytes 4 and 5 need to mathematically applied to find the product with .125 rpm / bit to get the right rpm. (byte 4 being the least )
basically how can we tap the can info on the USB port that does not fall on the usual com port but on the kvaser com port as we see it using the device manager.
appreciate if a sample code be shared to start bit by bit programming to be used on a C# .
Sincerely
|
|
|
|
|
Here[^] seem to be a load of examples.
noop()
|
|
|
|
|
Hi Phil , could not find the proper answer to the query ,,,,thanks anyways
kind regards
FIROZ
|
|
|
|
|
I need to do simulated annealing for facility planing with c# codes .. Im tryig but I couldnt
|
|
|
|
|
... and? You never asked a question or described any kind of problem, so it's pretty much impossible top guess what you're looking for.
|
|
|
|
|
It's time for you to get to work: now !
What research have you done on simulated annealing ? What algorithms have you implemented in what languages ?
You show us code; you ask specific questions about the code; you include error messages, and analysis of what you think is happening.
Then ... we help you.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I'm sure it is important - to you - but it's equally important that what you submit as your final project is your own work, not ours.
So if you have a problem, we'll help - but you have to show us what you have done. We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
If you "couldn't", change your major to something you can handle. Maybe French Literature, or Janitorial Science.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Hi all,
imagine this scenario:
- a tree structure is to be be built (edit/insert/delete nodes) by a group of several users
- the tree is expected to be quite large once finished (~100.000 nodes!)
- inserting, moving, copying/pasting nodes is required
- child nodes can result from individual requirements ("make a child node named A") or
from applying domain values (e.g. countries, currencies etc): "make child nodes for the
countries I select in a list".
My ideas so far:
- parent-child database table on MS SQL
- tree versioning similar to a sourcecode management system; each "check in" makes a new tree
version, so that older versions are present (for comparison, as copy/paste source)
- display in a multicolumn treeview using Infragistics Ultracontrols' UltraTree (present)
- nesting is done by parentID, and order of siblings (=children of the same parent)
is controlled by an additional integer value, so it can be changed ("move up/down").
Main problems:
- concurrency managment: my initial approach (timestamps for optimistic locking) could lead to
"outdated" branches, so that hours of work could not be saved, as the database status is newer
- key generation: classical parent-child-trees need keys to be referenced. Usually, I use
identity integer values in hierarchical dataset, so new nodes (-1, -2, -3) get their IDs on
dataset.Update, but here, the reference is recursive (not just hierarchical). Creating a branch
has to create the nodes "top down".
Of course, if a commercial solutions provides a way to edit/manage a huge tree with several users, I'd be glad not to have to reinvent the wheel.
Any ideas or hints?
Thanks!
Martin
|
|
|
|
|
That's not hard to ... imagine. But, imagining a single developer implementing this ... who is not already a wizard with an advanced DB that supports the features you describe ... that's hard.
There's lots of $ implementations out there: at the low end, checkout TreePad.
You might look into graph databases like Neo4j, or Amazon AWS Neptune (cloud), if you foresee the need for a highly connected set of entities where creating/manipulating linkages between nodes is critical.
A recent overview of graph DB's: [^]
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 11-May-19 22:15pm.
|
|
|
|
|
Thanks, I'll have a look at these.
Maybe my replies to the others' Posts may provide deeper insight.
modified 13-May-19 8:33am.
|
|
|
|
|
atrus2711 wrote: Maybe my replies to the others' Posts may provide deeper insight. ... uhhh ... no ... I keep bumping into too many other blind wise men in the room with the elephant
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Sorry, doesn't sound like an application.
atrus2711 wrote: child nodes can result from individual requirements ("make a child node named A") or
from applying domain values (e.g. countries, currencies etc): "make child nodes for the
countries I select in a list". From what list in which application? Let me guess, a "domain value" can be anything? The reason I'm sceptical is because I've seen this before; a tree that should hold everything (and then the spec stops).
atrus2711 wrote: - display in a multicolumn treeview using Infragistics Ultracontrols' UltraTree (present) Yuck. A treeview with a datagridview next to it would work better and probably perform better. You want to mix extra data (unknown # of columns) into a tree, displayed in a single control. I'd be going for a simple tree, loading only the expanded nodes, and only fetching the data for the grid on the selected node.
atrus2711 wrote: - concurrency managment: my initial approach (timestamps for optimistic locking) could lead to
"outdated" branches, so that hours of work could not be saved, as the database status is newer Most people lock the stuff that edited. If they are inserting the same info, then there's a problem with the workflow, not the application.
atrus2711 wrote: - key generation: classical parent-child-trees need keys to be referenced. Usually, I use
identity integer values in hierarchical dataset, so new nodes (-1, -2, -3) get their IDs on
dataset.Update, but here, the reference is recursive (not just hierarchical). Creating a branch
has to create the nodes "top down". You can still use a unique number, you just can't expect those numbers to stay sequential in the database. People will move branches, delete them; so the numbering won't stay consistent in the db.
Also, users don't like to have to expand over 10 branches just to get to their data. If the only stuff they work on is hidden three levels deep, I'll bet you that they want the tree to open THERE, without including all the stuff they're not using.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks for your post.
The tree is a chart of accounts for a financial company, i.e. the root items are things like "assets", "liabilities", "Profit and loss" and "Notes", each of them having thousands (!) of sub-branches. The leafs are to be booked on to, the non-leafs are sums.
You don't want to know how this giant tree is built up to today.
Quote: Let me guess, a "domain value" can be anything
The whole tree consists of nodes which are "bookable accounts or "sum positions". Each of them can result from different reasons. E.g. some node might Need breakdown in currencies, another one is detailed in customer groups. The reasons vary, as the lawmakers/regulatory authorities' mind changes.
Quote: Yuck. A treeview with a datagridview next to it would work better and probably perform better.
For input, yes. But the tree has to show several columns and once, which the built-in treeviews in MS VisualStudio do not provide.
Quote: Most people lock the stuff that edited.
Not here, as the whole account plan has to be built and seen. A position like "other" might occur several times, but is not expressive itself: it's only the "fullpath" that Shows what the Position is talking about. "others" might be other customer types, currencies, ...
Quote: You can still use a unique number, you just can't expect those numbers to stay sequential in the database. People will move branches, delete them; so the numbering won't stay consistent in the db.
There's no need for sequential numbers. The Position in the tree would be determined by parentID and "location within siblings". Yet, the Keywould either be created by the database, resulting in a timelag between node Insertion and db roundtrip, or the Client would create a key itself (e.g. a GUID).
Quote: Also, users don't like to have to expand over 10 branches just to get to their data. If the only stuff they work on is hidden three levels deep, I'll bet you that they want the tree to open THERE, without including all the stuff they're not using.
I wish it was like this. Tree partitions are meaningless, as explained just above....
Maybe my replies to the others' Posts may provide deeper insight.
modified 13-May-19 8:32am.
|
|
|
|
|