Click to See Complete Forum and Search --> : Database only updates if choose a diffrent row


brocky
September 20th, 2002, 03:56 AM
Database only updates if choose a diffrent row,

I have a datagrid wich is bound to a dataset.
If change now something in the grid an call
the dataadapter to update the database with the dataset
it only updates it if i selected a other row in the datagrid.
It also works ok if i select a diffrent control in my from and than call the update function.

Any ideas how i can do this programmatical?
I tried using i.e. listbox1.Select(), before i call the update
Well that works optical but somehow its diffrent because ths databse
still does not update only if i slect the other control or row by hand.

thanks in advance

here a Code snippet of my datagrid class and jow i call the update


void OnMenuSaveClick(object obj, EventArgs ea)
{
listBox1.Select();
listBox1.AddLog("Es wurde auf Speichern gedrückt");
dataGrid1.SaveCurrentGrid();
}




using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace ATGParaTool
{
/// <summary>
/// Zusammendfassende Beschreibung für SQLDataGrid.
/// </summary>
public class SQLDataGrid:DataGrid
{
DataSet dataSet = null;
OleDbConnection connection;
OleDbDataAdapter dataAdapter;
OleDbCommandBuilder custCB;

string strTabel;

public SQLDataGrid()
{
}
public void RefreshSQL(string strCaption, string strConnectString, string strSQLString)
{
connection = new OleDbConnection(strConnectString);
dataAdapter = new OleDbDataAdapter(strSQLString, connection);
custCB = new OleDbCommandBuilder(dataAdapter);


dataSet = new DataSet();
DataGridTableStyle dgts = new DataGridTableStyle();
strTabel = strCaption;

dataSet.Clear();
dataAdapter.Fill(dataSet, strCaption);
CaptionText = strCaption;
DataSource = dataSet.Tables[strCaption].DefaultView;

dgts.MappingName = strCaption;
dgts.BackColor = Color.Beige;
dgts.AlternatingBackColor = Color.AliceBlue;


TableStyles.Clear();
TableStyles.Add(dgts);


#region Die Weite der Spalten anpassen
for(int col=0; col < dataSet.Tables[strCaption].Columns.Count; col++)
{
float width = 0;
int numRows = dataSet.Tables[strCaption].Rows.Count;

Graphics g = Graphics.FromHwnd(this.Handle);
StringFormat sf = new StringFormat(StringFormat.GenericTypographic);
SizeF size;

for(int i = 0; i < numRows; ++ i)
{
size = g.MeasureString(this[i, col].ToString(), this.Font, 500, sf);
if(size.Width > width)
width = size.Width + 15;
}

g.Dispose();

this.TableStyles[strCaption].GridColumnStyles[col].Width = (int) width;
}
#endregion

CurrencyManager cm = (CurrencyManager)this.BindingContext[DataSource, DataMember];
((DataView)cm.List).AllowNew = false;
}

public void SaveCurrentGrid()
{

if(dataSet != null)
{
if(dataSet.Tables[strTabel].Rows.Count > 0)
{
dataAdapter.Update(dataSet, strTabel);
}
}
}
}
}