|
|
Hi everyone,
I am writting an program in C#, that use SQL Server database.
My program include a blank database (sample database) that allow users can create a new database.
For example:
- User 1 use my program to create a new database (DB1) on his computer, then he import/enter some data into DB1
- User 2 use my program to create a new database (DB2) on his computer, then he import/enter some data into DB2
Now, I have both two database (DB1, DB2). Do you know how to merge/combine two databases to have unique database that contain all users' data ?
Can you help me ?
Thank you very much,
Tai
|
|
|
|
|
|
i´m trying to bind a list to a datagridview. i do that:
public void seedatagrid(List<myClass> liste2)
{
dgv_TraceItems.DataSource =liste2;
}
and the datagridview has the data, but it doesn´t show anything.
could you help me?? how can i resolve the problem?? thank you
the class
public enum TYPE
{
normal= 1,
especial= 3,
low= 6,
high= 7,
}
public class myClass : INotifyPropertyChanged
{
private byte number;
private TYPE type;
private string file;
private bool isselected;
public event PropertyChangedEventHandler PropertyChanged;
public byte Number
{
get
{
return this.number;
}
set
{
this.number= value;
this.OnPropertyChanged("Number");
}
}
public TYPE Type
{
get
{
return this.type;
}
set
{
this.type = value;
this.OnPropertyChanged("Type");
}
}
public string File
{
get
{
return this.file;
}
set
{
this.file = value;
this.OnPropertyChanged("File");
}
}
public bool IsSelected
{
get
{
return this.isselected;
}
set
{
this.isselected = value;
this.OnPropertyChanged("IsSelected");
}
}
public myClass(UInt32 Data, string Text)
{
this.number = (byte)((Data & 0x0000FF00) >> 8);
this.type = (TYPE)((Data & 0x00FF0000) >> 16);
this.file = Text;
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
i have tried to make a datatable with the list and the datagridview doesn´t show anything. i don´t know what happends , but i have a problem with the datagridview
|
|
|
|
|
Some things to look at:
* is it Asp.Net? I remember back in the days you also had to call the databind method. Not sure if it changed in newer versions.
* Is the datagridview "aligned" with the source you put into it? IOW the values of the class are not appended at the end of the grid (column wise) or the datagridview doesn't know what to do with the properties you're putting in? In short, you're pumping in a block of data, but you need to tell the datagridview what parts of the data are for which column.
Hope this helps.
|
|
|
|
|
ok, i understand you say,but i don´t know how to make it, hehe
how can i tell the datagridview what parts of the data are for which column?
with a list or with a datatable there is a problem with the datagridview.
because if a make a datatable with the list (all as string) and after i send the datatable to the datagridview, and the datadrigview doesn´t show anything. what problem is??
thank you
|
|
|
|
|
If you haven't defined any columns in the designer it should do this for you, no problems. If you did define columns I guess you also need to define the "link" to the data you're attaching. You can do this in the designer and in code I guess (it's been a while since I did this).
I would try to find some samples on MSDN.
|
|
|
|
|
i have definde any columns, but i tried too columns definded, but it´s the same.
any sample would be helper
thank you
|
|
|
|
|
I would try to find some samples on MSDN.
|
|
|
|
|
i have definde any columns, but i tried too columns defined, but it´s the same.
any sample would be helper
thank you
|
|
|
|
|
Start by using the debugger: put a breakpoint on the line:
dgv_TraceItems.DataSource =liste2;
and check that the list contains class instances.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
hi,
i have a breakpoint there and it contains all, and the datagridview too.
dgv_TraceItems.DataSource Count=9
but it shows nothing.
|
|
|
|
|
Where is seedatagrid being called from?
It's perfectly valid to just set the DataGridView.DataSource to a list of class instances, and the system should (and does) pick out the public properties and display them in columns. I do it all the time, especially for testing, so I know it works without any supporting code.
Try this:
dgv_TraceItems.DataSource = new List<string> { "hello", "goodbye" }; You should get two rows of one column, with values 5 and 7.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
i tried
dgv_TraceItems.DataSource = new List<string> { "hello", "goodbye" };
datasource contains "hello", "goodbye", but it shows also nothing, do i have a problem with the configuration of my datagridview??
thank you
|
|
|
|
|
OK - we've eliminated data as a possible cause, so that leaves us two things: first it's being called in the wrong place - so where is it being called from? What event or top level method?
Do you get any rows at all? Any column headers?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
public void seedatagrid(List<myClass> liste2)
{
dgv_TraceItems.DataSource =liste2;
}
this funtcion is called in Form1.cs and goes to table layout panel where is the datagridview.
i get any rows and any column headers.
thank you for helping
|
|
|
|
|
Yes - but it will be called from a method - it isn't an event handler so it has to be called from somewhere - like the form constructor, or a button click handler, or similar.
"i get any rows and any column headers." does this mean you do, or you don't? If you do, how many of each?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
void pChannelKonfig_EnabledChanged(object sender, EventArgs e)
{
list_to_dgv.seedatagrid(testInfo.Information);
}
i call it here. testinfo is the name of a class and Information is th List
|
|
|
|
|
OK - so is list_to_dgv a form, or what? Because if it is, you need to make sure it is the right instance of the form as is currently displaying, because the seedatagrid code will set the DGV on the specific class instance you call it on. So if you aren't using the right list_to_dgv, then the DGV will get the data, but the DGV itself isn't displaying, because the form it is part of isn't displaying - which would explain your problem!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
this is testInfo class:
public class TestInfoClass : INotifyPropertyChanged
{
private string fileName;
private List<BLF_InfoClass> information;
public event PropertyChangedEventHandler PropertyChanged;
public string FileName
{
get
{
return this.fileName;
}
set
{
this.fileName = value;
this.OnPropertyChanged("BlfFileName");
}
}
public List<InfoClass> Information
{
get
{
return this.information;
}
set
{
this.information = value;
this.OnPropertyChanged("Information");
}
}
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
and this is list_to_dgv (UC_Configuration is a Form)
public partial class UC_ChannelConfiguration : UserControl
{
public UC_ChannelConfiguration()
{
InitializeComponent();
}
public void seedatagrid(List<BLF_InfoClass> liste2)
{
dgv_TraceItems.DataSource = liste2;
}
}
|
|
|
|
|
So...
list_to_dgv is a UC_ChannelConfiguration instance,
and it's embedded in a UC_Configuration form instance.
Yes?
So that means that pChannelKonfig_EnabledChanged is an event handler within the UC_Configuration form, and that you have just the one single instance of the form ever created, and one UC_ChannelConfiguration
instance inserted in the designer? Or do you manually create those, since you were earlier talking about a TableLayoutPanel?
Basically, all the code you have shown should work: so the chances are it is working - but it's probably affecting an instance of the DGV that you can't see, and I can't see enough of your code to work out which one it is affecting, so I'm trying to ensure that we are talking about exactly the same situation rather than me assuming stuff you already know and getting it wrong.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
public partial class MainForm : Form
{
ParserClass file = null;
UC_ChannelConfiguration list_to_dgv = new UC_ChannelConfiguration();
TestInfoClass testInfo = null;
public MainForm()
{
InitializeComponent();
testInfo = new TestInfoClass();
testInfo.PropertyChanged += new PropertyChangedEventHandler(testInfo_PropertyChanged);
tbTraceFile.DataBindings.Add(new Binding("Text", testInfo, "FileName"));
pConfig.EnabledChanged += new EventHandler(pConfig_EnabledChanged);
}
void pConfig_EnabledChanged(object sender, EventArgs e)
{
list_to_dgv.seedatagrid(testInfo.Information);
}
private void btlLoadfile_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog_file = new OpenFileDialog();
openFileDialog_file .RestoreDirectory = false;
openFileDialog_file .Multiselect = false;
if (openFileDialog_file .ShowDialog() == DialogResult.OK)
{
testInfo.FileName = openFileDialog_file.FileName;
}
}
}
thank you very much for your time and for helping me.
i think with this, you have all my code, if you need any more, please say.
because i don´t know how to resolve this
|
|
|
|
|
Um. My friend...you aren't displaying the UC_ChannelConfiguration list_to_dgv at all - you create a new instance of it, that's fine - but unless that is added as part of the Form.Controls collection (or to an item in that collection) it will never be displayed - so whatever DGV you are looking at on the form when you run your app - it isn't the same one you are loading data into via seedatagrid !
Do you have an additional UC_ChannelConfiguration loaded in the designer? If so, try using that one instead!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
thank you very much!!!
finally i used Bindinglist and a new instance as you said me.
thank you very much
|
|
|
|
|
You're welcome!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|