Thanks for the input . will try this, but i have another question.
i have to show the ID values of table1 as column captions and ID
values of table2 as the 1st column of the data grid view.
I have already done this by bring data from the server of table1 and
table2 and the looping through the two table and adding columns and
rows to the grid view. like below
foreach (DataRow currow in table1.Rows)
{
datagridview1.Columns.Add(currow["ID"].ToString(),currow["ID"].ToString());
}
foreach (DataRow currow in table2.Rows)
{
datagridview1.Rows.Add(currow["ID"].ToString());
}
But how can i put the data in table3 in the to the data grid view to
show it in the correct place. i can't just bind the data grid view to
the table3, then i lose my column and row data.
Is the method i'm using to add the columns and rows correct? Is there
a better method to do this?
On Oct 13, 9:07 am, sallushan <[EMAIL PROTECTED]> wrote:
> I little thing I missed,
>
> // if this row is NOT entered yet
> if (rows == null) {
> r = table3.NewRow();
> r("id1") = c1value;
> r("id2") = c2value;
> table3.Rows.Add(r); // ************ ADD THIS LINE
> ********************
> }
> else {
> r = rows(0);
> }
>
> On Oct 13, 9:01 am, "Arsalan Tamiz" <[EMAIL PROTECTED]> wrote:
>
> > Having same interface as you have created, use the DataGridView's
> > CellEndEdit Event. Whenever any value is given you will be notified. So the
> > logical can be,
>
> > private void DataGridView1_CellEndEdit(object sender,
> > System.Windows.Forms.DataGridViewCellEventArgs e)
> > {
> > object c1value = null;
> > object c2value = null;
>
> > // we know which column has been edited so this will be the row
> > // from Table1 and we know which row has been edited so this
> > // will be the row from table2
> > c1value = table1.Rows(e.ColumnIndex - 1)("id1");
> > c2value = table2.Rows(e.RowIndex)("id1");
>
> > DataRow[] rows = null;
> > DataRow r = default(DataRow);
> > // ok now we are checking whether the value has already been entered
> > // in our Table3 or NOT
> > rows = table3.Select("id1=" + c1value + " AND id2=" + c2value);
> > // if this row is NOT entered yet
> > if (rows == null) {
> > r = table3.NewRow();
> > r("id1") = c1value;
> > r("id2") = c2value;
> > }
> > else {
> > r = rows(0);
> > }
>
> > r("value") = DataGridView1(e.ColumnIndex, e.RowIndex).Value;
>
> > }
>
> > So just send the Table3 to the DataAdapter/TableAdapter which will update
> > the Physical Database
>
> > On Sun, Oct 12, 2008 at 5:57 AM, I~N~S~I <[EMAIL PROTECTED]> wrote:
>
> > > Hi all,
> > > I have this problem, i need to know is there a way i cn use the data
> > > adapter's update method in this scenario.
> > > i have 3 tables as below
>
> > > create table table1{
> > > id1 int identity(1,1)
> > > Constraint pk_table1 Primary Key,
> > > title varchar(20) not null,
> > > }
>
> > > create table table2{
> > > id2 int identity(1,1)
> > > Constraint pk_table1 Primary Key,
> > > title varchar(20) not null,
> > > }
>
> > > create table table3{
> > > id1 int not null
> > > Constraint fk_table3_1 Foreign Key References
> > > table1(id1),
> > > id2 int not null
> > > Constraint fk_table3_2 Foreign Key References
> > > table2(id2),
> > > value int default 0,
> > > Constraint pk_table3 Primary Key (id1,id2),
> > > }
>
> > > In my application i have a Datagrid view, which has all the records
> > > of
> > > table1 as the columns of the datagrid view and records of table2 as
> > > the rows of the data grid. and i have table 3 to store the values i
> > > enter in Datagrid view.
>
> > > I was wondering can i use the data adapter to fetch data of table3
> > > using Fill method and use da update method of data adapter to add
> > > values to table3.
>
> > > I have no leads on how to start, thats why my 1st have the concern
> > > whether i can do it using the Data adapter.
>
> > > The only method i cn think of is loop through each cell im my
> > > datagrid
> > > view and manually run the insert or update SQL commands. But that
> > > will
> > > make my application very slow. specially when there is abt 40 records
> > > in table1 and 100 records in table2... :-(
> > > Can anyone giv me any leads.....
>
> > > P.S: Im using C# and SQL server 2000 / 2005
>
> > > Thank you,
> > > Insira.- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/DotNetDevelopment
You may subscribe to group Feeds using a RSS Feed Reader to stay upto date
using following url
<a href="http://feeds.feedburner.com/DotNetDevelopment">
http://feeds.feedburner.com/DotNetDevelopment</a>
-~----------~----~----~----~------~----~------~--~---