 |
|
 |
How to find in a datagridview?
|
|
|
|
 |
|
 |
Thank you for your article, it really helped me since I am completely new to C# and programming in general. However, I didn't manage to fully understand how I was to drag the table in the database that I am going to work on onto the form to create the Data Adapter, Connection and Command. Thank you.
Simon
|
|
|
|
 |
|
 |
Choose the table from Server Explorer, and drag drop it to your form.
|
|
|
|
 |
|
 |
Thanks for your reply
I am using SQL Server and can only find a database explorer. Is that the same as Server Explorer? When I try to drag the table in the database in the database explorer to the designer of the form, my cursor changes to a black circle with a line through it, indicating that I cannot drop that there. I assume I am not supposed to drop it on the designer of the form?
Simon
|
|
|
|
 |
|
 |
Hmm, I think it is best for you to open the application to see what is the code for SqlConnection, SqlDataAdapter, and SqlCommand. So you manually create it.
|
|
|
|
 |
|
 |
I am having the same problem as Simon had. I created the database using "Database Explorer" (Your Server Explorer is the same as Database Explorer in C# 2008 Express as per help in C# Express). I discovered your database db1.mdb in your file at the beginning of the instructions so I just used that database. That now puts me into a OLEDB database (ex. OleDbConnection, OleDbDataAdapter and OleDbCommand) not an SQL database - correct? I have opened the app. What exactly am I looking for in this app that would assist me in furthering Step 1? Are we suppose to manually create the form in the app?
|
|
|
|
 |
|
 |
feel proud when im searching on this and found that indonesian who wrote this article..
keep on moving bro..
anyway..i got a some problems on asp.net..
would u help me,if u dont mind,goodmaster?hehe..
|
|
|
|
 |
|
 |
ebelebelebel wrote: feel proud when im searching on this and found that indonesian who wrote this article..
Hello. You're an Indoenesian? Live in Germany?
Sorry couldn't help you with asp.net. I don't have enough knowledge on that. Try the forum.
|
|
|
|
 |
|
 |
yes, but just doing my praktikum..
owh..ic..no problem.. what's ADO.net use for? sounds unfamiliar for me..
where do you live aniway?
|
|
|
|
 |
|
 |
Still live in Indonesia. I see that you're still very young. Great. ADO.NET is for database. I usually use it with C#.
|
|
|
|
 |
|
 |
I have a problem with coping DataRow. But let's start from beginning. I have a typed DataSet with a lot of tables in it. There is a main table which has a child tables, and some of those also has children. So basically there are only parent-child relations. Now I need to make a copy of main table row with all it's children and children's children and put it to same DataSet. All new rows should have state "Added".
Thanks in advance.
------
There are 10 kind of people those who understand binary and those who not. - Some binary freak.
|
|
|
|
 |
|
 |
What's the code? What's the problem(error)? Have you tried catching the error? Probably it's because the duplicate constraint.
|
|
|
|
 |
|
 |
I rather had a way of doing it in mind... not the error. But by the way. I have one if something goes wrong. Check out the catch block.
private void CopyCurrentRow()
{
DataSet transaction = dataSet.GetChanges();
try
{
EndEditAll();
DataRowView drv = MainBindingSource.Current as DataRowView;
if (drv == null || drv.Row == null)
return;
dataSet.MainRow orgMainRow = drv.Row as dataSet.MainRow;
DataRow[] orgRel1Rows = orgMainRow.GetChildRows("FK_Rel1_Main");
DataRow[] orgRel2Rows = orgMainRow.GetChildRows("FK_Rel2_Main");
DataRow[] orgRel3Rows = orgMainRow.GetChildRows("FK_Rel3_Main");
Hashtable orgRel3_1RowsHT = new Hashtable();
Hashtable orgRel3_2RowsHT = new Hashtable();
if (orgProd1Rows != null)
{
foreach (DataRow dr3_1 in orgProd1Rows)
{
DataRow[] orgRel3_2Rows = dr3_1.GetChildRows("FK_Rel3_Rel3_1");
orgRel3_1RowsHT[dr3_1] = orgRel3_2Rows;
if (orgProd2Rows != null)
{
foreach (DataRow dr3_2 in orgProd2Rows)
{
DataRow[] orgRel3_3Rows = dr3_2.GetChildRows("FK_Rel33_1_Rel3_2");
orgRel3_2RowsHT[dr3_2] = orgRel3_3Rows;
}
}
}
}
DataRow newMainRow = CopyRow(dataSet.Main, orgMainRow);
foreach (DataRow dr in orgRel1Rows)
{
DataRow newDr = CopyRow(dataSet.Rel1, dr);
newDr.SetParentRow(newMainRow);
}
foreach (DataRow dr in orgRel2Rows)
{
DataRow newDr = CopyRow(dataSet.Rel2, dr);
newDr.SetParentRow(newMainRow);
}
foreach (DataRow dr in orgRel3Rows)
{
DataRow newDr = CopyRow(dataSet.Rel3, dr);
newDr.SetParentRow(newMainRow);
DataRow[] Rel1childs = (DataRow[])orgProd1childRows[dr];
if (Rel1childs != null)
{
foreach (DataRow dr2 in Rel1childs)
{
DataRow newDr2 = CopyRow(dataSet.Rel3_2, dr2);
newDr2.SetParentRow(newDr);
DataRow[] Rel2childs = (DataRow[])orgProd2childRows[dr2];
if (Rel2childs != null)
{
foreach (DataRow dr3 in Rel2childs)
{
DataRow newDr3 = CopyRow(dataSet.Rel3_3, dr3);
newDr3.SetParentRow(newDr2);
}
}
}
}
}
AutoSaveData();
MainBindingSource.MoveLast();
}
catch (Exception ex)
{
dataSet.RejectChanges();
dataSet.Merge(transaction);
ExceptionHandler.ShowMessage(ex);
}
}
private DataRow CopyRow(DataTable schemaAndDataDataTable, DataRow dataRowToCopy)
{
DataRow dr = schemaAndDataDataTable.NewRow();
foreach (DataColumn dc in schemaAndDataDataTable.Columns)
{
if (!dc.Unique && !dc.AutoIncrement)
dr[dc] = dataRowToCopy[dc];
}
schemaAndDataDataTable.Rows.Add(dr);
return dr;
}
------
There are 10 kind of people those who understand binary and those who not. - Some binary freak.
|
|
|
|
 |
|
 |
So what's the error which you catch? I haven't check the code carefully. From the error message, you should be able to figure out what went wrong.
|
|
|
|
 |
|
 |
I have working app at home, so I can't tell you now. It this error occurs again I will check it out and post it here (With problem solution I think)
This code is a sample code which actually haven't bee tested.. you can say it's a overview of the solution (I suppose that there is a bug in it.)
Exception was about some rows not being in the collection. It might be caused by constrains, but the funny part is that I had an error in the code before operations so problem was inside changes that i stored and not the operations.
DataSet transaction = dataSet.GetChanges();
dataSet.RejectChanges(); dataSet.Merge(transaction);
I don't have time to test it now... I'm at work
------
There are 10 kind of people those who understand binary and those who not. - Some binary freak.
|
|
|
|
 |
|
 |
Anyway, you should be able to find the problem, looking from the error message.
dr4cul4 wrote: I don't have time to test it now... I'm at work
So what's the code for? Not for work? I saw your profile. You were saying that you didn't get much from your job. Why don't making your own business, then you can have control of your life.
|
|
|
|
 |
|
|
 |
|
 |
Hi,
First, let me say I'm the sort of person that really likes to have some form of discussion when it comes to the code. If you're not going to discuss the code in any great detail in your article, at least comment your source. Please.
Secondly, re-reading all data from the database each time you select a record is a bad idea performance-wise (it also defeats the purpose of having a disconnected data source). You would be better off binding the text boxes to the related fields in your dataset and then navigating through the records like so:
this.BindingContext(dataSet11, "Student").Position = 0; // move to first record
this.BindingContext(dataSet11, "Student").Position += 1; // move to next record
this.BindingContext(dataSet11, "Student").Position -= 1; // move to previous record
The BindingContext property is a property of the form.
By setting the Position property you control what record you are "viewing" in the DataSet. Because your text boxes are bound to the dataset, changing the Position property changes the values displayed.
Regards,
-Adam.
|
|
|
|
 |
|
 |
Thank you, Adam.
Work hard, Work effectively and a bit of luck is the key to success.
|
|
|
|
 |
|
 |
FYI, your demo project is getting a lot of unhandled exceptions. I'm not going to rate this now, because it's new and clearly needs a little modifcation. Other then that your article looks good.
|
|
|
|
 |
|
 |
Did the application also has unhandled exception? What exception in the demo project?
Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
 |
|
 |
In the demo application, click on a null row... This causes things to go down hill. It should be a quick fix.
|
|
|
|
 |
|
 |
Done
Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
 |
|
 |
Looks good, I went a head and gave a good rating. I will say that some people might find your article a little thin on discussion, but I personally don’t care as long as there is good solid code to learn from. One additional thing, you might consider moving the file, db1.mdb, up one folder or adding another copy in the debug folder.
|
|
|
|
 |
|
 |
Thanks.
ACorbs wrote:
adding another copy in the debug folder.
I was thinking about that, but I change my mind. It would be bigger in size.
Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
 |