V
vblover29
Guest
I have a datagridview bound to a bindingsource and I want to add an empty row to the datagridview allowing the user to input the data in the different columns. While updating to the Database, it seems there is an extran empty row and it contradicts the nonnull constraint. Thanks. Here is the code:
/////////////////////////////////////////////////////////////////////////////
In the form load
////////////////////////////////////////////////////////////////////////////
obj_CmdFournisseur.Connection = G_ObjconnectionFixe
obj_DataFournisseur = New SqlDataAdapter(obj_CmdFournisseur)
' Create a command builder object
Obj_Builder = New SqlCommandBuilder(obj_DataFournisseur)
Obj_Builder.QuotePrefix() = "["
Obj_Builder.QuoteSuffix = "]"
obj_DSFournisseur.Clear()
obj_DataFournisseur.Fill(obj_DSFournisseur, "fournisseurs")
With ComboBox1.Items
.Add("Tous")
.Add("Actifs seuls")
.Add("Effaces seuls")
.Add("Solde positif")
.Add("Solde negatif")
End With
IsFirstUseofAllOption = True
ComboBox1.SelectedIndex = 0
///////////////////////////////////////////////////////////////////
In the combobox1 selectedindexchanged
///////////////////////////////////////////////////////////////
With ComboBox1
Select Case .SelectedIndex
Case Is = 0 ' option tous
DataViewFournisseurs = New ataView(obj_DSFournisseur.Tables("fournisseurs"))
DtTable = DataViewFournisseurs.ToTable()
Str_Filtre = ""
Bl_ButtonState = True
bsSource.SuspendBinding()
bsSource.DataSource = DataViewFournisseurs
bsSource.Filter = Str_Filtre
bsSource.Sort = "[nom fournisseur] ASC"
bsSource.ResumeBinding()
With DataGridView1
.DataSource = bsSource
End With
///////////////////////////////////////////////////////////////////////////
In the add button
///////////////////////////////////////////////////////////////////////////
Dim Obj_NewRow As DataRow
Obj_NewRow = obj_DSFournisseur.Tables("fournisseurs").NewRow
Obj_NewRow.Item("nom fournisseur") = ""
Obj_NewRow.Item("adresse") = ""
Obj_NewRow.Item("ville") = ""
Obj_NewRow.Item("telephone") = ""
Obj_NewRow.Item("solde") = 0.0
Obj_NewRow.Item("efface") = False
obj_DSFournisseur.Tables("fournisseurs").Rows.Add(Obj_NewRow)
Continue reading...
/////////////////////////////////////////////////////////////////////////////
In the form load
////////////////////////////////////////////////////////////////////////////
obj_CmdFournisseur.Connection = G_ObjconnectionFixe
obj_DataFournisseur = New SqlDataAdapter(obj_CmdFournisseur)
' Create a command builder object
Obj_Builder = New SqlCommandBuilder(obj_DataFournisseur)
Obj_Builder.QuotePrefix() = "["
Obj_Builder.QuoteSuffix = "]"
obj_DSFournisseur.Clear()
obj_DataFournisseur.Fill(obj_DSFournisseur, "fournisseurs")
With ComboBox1.Items
.Add("Tous")
.Add("Actifs seuls")
.Add("Effaces seuls")
.Add("Solde positif")
.Add("Solde negatif")
End With
IsFirstUseofAllOption = True
ComboBox1.SelectedIndex = 0
///////////////////////////////////////////////////////////////////
In the combobox1 selectedindexchanged
///////////////////////////////////////////////////////////////
With ComboBox1
Select Case .SelectedIndex
Case Is = 0 ' option tous
DataViewFournisseurs = New ataView(obj_DSFournisseur.Tables("fournisseurs"))
DtTable = DataViewFournisseurs.ToTable()
Str_Filtre = ""
Bl_ButtonState = True
bsSource.SuspendBinding()
bsSource.DataSource = DataViewFournisseurs
bsSource.Filter = Str_Filtre
bsSource.Sort = "[nom fournisseur] ASC"
bsSource.ResumeBinding()
With DataGridView1
.DataSource = bsSource
End With
///////////////////////////////////////////////////////////////////////////
In the add button
///////////////////////////////////////////////////////////////////////////
Dim Obj_NewRow As DataRow
Obj_NewRow = obj_DSFournisseur.Tables("fournisseurs").NewRow
Obj_NewRow.Item("nom fournisseur") = ""
Obj_NewRow.Item("adresse") = ""
Obj_NewRow.Item("ville") = ""
Obj_NewRow.Item("telephone") = ""
Obj_NewRow.Item("solde") = 0.0
Obj_NewRow.Item("efface") = False
obj_DSFournisseur.Tables("fournisseurs").Rows.Add(Obj_NewRow)
Continue reading...