|
I am working on a program that will search for files and add the files to a listbox(listbox1). Here is the code:
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
GetDirectoryContents(TextBox1.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries), TextBox2.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries))
End Sub
Private Sub GetDirectoryContents(ByVal dirs() As String, ByVal patterns() As String)
'Declare variable.
Dim dDir As DirectoryInfo
For Each sDir As String In dirs
If Not Directory.Exists(sDir) Then Continue For
dDir = New DirectoryInfo(sDir)
For Each ext As String In patterns
For Each fi As FileInfo In dDir.GetFileSystemInfos("*." & ext)
ListBox1.Items.Add(fi.Name)
Next
Next
Next
End Sub
I have created a table in access named tblExcluded which includes excluded files. I want to be able to check that table to see if specific files are in the table. If those files are in the table then add them to listbox2 and all other files that don't exist in the table store then in listbox1. The table contains a ID field and a the file path field. Does any one have any sample code that will perform this? Any suggestions would help.
|
|
|
|
|
I think my brain is turning to mush over this. Ive been looking at events and the order that they're fired to figure out the best place to control the entries in the comboboxes and textboxes. By allowing databinding through the textboxes I need to stop the user from changing rows if they havent entered everything correctly BUT if I use the CellValidating and call e.Cancel = True then obviously that prevents ALL events from completing because even closing the form calls the cell validating event.
So I would appreciate any suggestions regarding how to validate the entries and prevent the row from being changed (since it then attempts to save the value in the row being switched from) without preventing the form from being closed etc...
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Maybe I am missing something here, but in your datatable and dataset on the back end which is where the data should be changing, you have to call AcceptChanges() for the dataset to keep those changes. You can always call RejectChanges() and rebind the datagridview and their stuff would not be saved. Maybe I am missing something.
Ben
|
|
|
|
|
Where would I call those methods? I just started messing around with the RowChanged event in the partial class of the dataset and that doesnt seem to set the errors correctly. I used to do this all by my own code but this time I am trying to keep working with what I inherited and that is a databound DataGridView and I have added the databound functionality to the textboxes and comboboxes in order to pull the editing out of the grid. The problem is that I am getting different errors than I have ever gotten since it tries to apply the update when the row changes and it is obviously happening before the form's grid's RowChanged and SelectionChanged events.
Like I said the CellValidating works but when I call e.Cancel = True it prevents all events from firing.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Well, if you want to continue to do it that way, you should probably be in a different event. The RowChanging event is where you could set the dataSet.AcceptChanges() or dataSet.RejectChanges(). RowChanging happens before the row is committed. Once you get to RowChanged the Row has already been changed unless you cancel.
Ben
|
|
|
|
|
The Row_Changing is not firing before I get the following.
---------------------------<br />
DataGridView Default Error Dialog<br />
---------------------------<br />
The following exception occurred in the DataGridView:<br />
<br />
<br />
<br />
System.Data.NoNullAllowedException: Column 'ColumnName' does not allow nulls.<br />
<br />
at System.Data.DataColumn.CheckNullable(DataRow row)<br />
<br />
at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)<br />
<br />
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException)<br />
<br />
at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent)<br />
<br />
at System.Data.DataRow.EndEdit()<br />
<br />
at System.Data.DataRowView.EndEdit()<br />
<br />
at System.Windows.Forms.CurrencyManager.EndCurrentEdit()<br />
<br />
at System.Windows.Forms.CurrencyManager.ChangeRecordState(Int32 newPosition, Boolean validating, Boolean endCurrentEdit, Boolean firePositionChange, Boolean pullData)<br />
<br />
at System.Windows.Forms.CurrencyManager.set_Position(Int32 value)<br />
<br />
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e)<br />
<br />
<br />
<br />
To replace this default dialog please handle the DataError event.<br />
---------------------------<br />
OK <br />
---------------------------
This comes up immediately and the only thing that fired before it was the CellValidating.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
It sounds like in your datatable you have a column where allownulls it set to false. The only time you should do that is if a default value is set that is not null or you have marked that column as an identity column. So when the insert happens if a column do not allow nulls and the default value is null you will get that error.
Ben
|
|
|
|
|
Alright, I set the AllowNulls to True and the DefaultValue to 0 and I still get the error. This .NET 2.0 binding is sooooooooo frustrating.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
It sort of was the first time I did it too. You get over these little gotchas and then it works nice. It is just the inital learning curve.
Well, according to your error message it is the columnName that does not allow nulls. So you must have a column in your datatable that doesn't have a name for some reason. I didn't read the error close enough the first time.
Ben
|
|
|
|
|
kubben wrote: Well, according to your error message it is the columnName that does not allow nulls. So you must have a column in your datatable that doesn't have a name for some reason. I didn't read the error close enough the first time.
Actually that is just the generic name I gave it when I posted the error message it is actually a quantity column. What I have is a form with the bound textboxes and some comboboxes as well. When the value is no present in the grid, say it is old data being pulled up again or for whatever reason that value is missing OR doesnt match any values in the drop downs. What it is doing is trying to place a blank/NULL in that column when the row is navigated away. What I am trying to do is prevent that navigation by setting an ErrorProvider on those input controls which works before the exception is thrown in the CellValidating portion only. But like I said I cant stop the navigation from there without affecting other events.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
Hai to All...
I want to write a chat application,where a user can chat with any other users in the network..and i want to write an application where more than one user can draw a picture via online chat...
for some example "X" user chatting with a user called "Y",user X is drawing a house picture at the same time user y can edit that picture...
Can any one tell me how to do this,plz help me on this project..
|
|
|
|
|
Why does every newbie want to write a chat application? Google says it's been done[^] about 1.8 million times.
|
|
|
|
|
Dave Kreskowiak wrote: Why does every newbie want to write a chat application?
No kidding
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Sadly I just saw another request on another board...
__________________
Bob is my homeboy.
|
|
|
|
|
leckey wrote: Sadly I just saw another request on another board...
Yeah, it was cross posted in the C# forum.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Yes i know....it's a really odd phenomenon.
Posted by The ANZAC
|
|
|
|
|
The ANZAC wrote: it's a really odd phenomenon
It is
|
|
|
|
|
Come on friends,try to read my question carefully,then try to do answer the question,instead of reading the question how can u play jokes...
if u can then try to give some suggestion... Ok
Mohan
|
|
|
|
|
Am Sending the who code Please Rearange it for me, am taking the old one., i want it to face SQL db for class module clsClient
<br />
<br />
<br />
Dim WithEvents adoPrimaryRS As Recordset<br />
Private DoingRequery As Boolean<br />
Public Event MoveComplete()<br />
Private Sub Class_Initialize()<br />
Dim sSQL As String<br />
Dim db As Connection<br />
Set db = New Connection<br />
db.CursorLocation = adUseClient<br />
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Db\Valroldb.mdb;"<br />
'sSQL = "Select Name from owner"<br />
Set adoPrimaryRS = New Recordset<br />
'GetOwner<br />
'If OpenCN Then<br />
If OpenCN Then<br />
adoPrimaryRS.Open BuiltSQL, CN, adOpenForwardOnly, adLockOptimistic<br />
<br />
DataMembers.Add "Primary"<br />
End If<br />
'db.Close<br />
'Set db = Nothing<br />
End Sub<br />
<br />
Private Sub Class_GetDataMember(DataMember As String, Data As Object)<br />
Select Case DataMember<br />
Case "Primary"<br />
Set Data = adoPrimaryRS<br />
End Select<br />
End Sub<br />
<br />
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)<br />
RaiseEvent MoveComplete<br />
End Sub<br />
<br />
Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)<br />
'This is where you put validation code<br />
'This event gets called when the following actions occur<br />
Dim bCancel As Boolean<br />
Select Case adReason<br />
Case adRsnAddNew<br />
Case adRsnClose<br />
Case adRsnDelete<br />
Case adRsnFirstChange<br />
Case adRsnMove<br />
Case adRsnRequery<br />
Case adRsnResynch<br />
Case adRsnUndoAddNew<br />
Case adRsnUndoDelete<br />
Case adRsnUndoUpdate<br />
Case adRsnUpdate<br />
End Select<br />
<br />
If bCancel Then adStatus = adStatusCancel<br />
End Sub<br />
<br />
Public Property Get EditingRecord() As Boolean<br />
EditingRecord = (adoPrimaryRS.EditMode <> adEditNone)<br />
End Property<br />
<br />
Public Property Get AbsolutePosition() As Long<br />
AbsolutePosition = adoPrimaryRS.AbsolutePosition<br />
End Property<br />
<br />
Public Sub Requery()<br />
adoPrimaryRS.Requery<br />
DataMemberChanged "Primary"<br />
End Sub<br />
<br />
Public Sub MoveFirst()<br />
If Not adoPrimaryRS.EOF And adoPrimaryRS.BOF Then<br />
adoPrimaryRS.MoveFirst<br />
End If<br />
End Sub<br />
<br />
Public Sub MoveLast()<br />
If Not adoPrimaryRS.EOF Or Not adoPrimaryRS.BOF Then<br />
adoPrimaryRS.MoveLast<br />
End If<br />
End Sub<br />
<br />
Public Sub MoveNext()<br />
If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext<br />
If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then<br />
Beep<br />
'moved off the end so go back<br />
adoPrimaryRS.MoveLast<br />
End If<br />
End Sub<br />
<br />
Public Sub MovePrevious()<br />
If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious<br />
If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then<br />
Beep<br />
'moved off the end so go back<br />
adoPrimaryRS.MoveFirst<br />
End If<br />
End Sub<br />
<br />
i want it to Point to
PROVIDER=SQLOLEDB
Server=sgiicornetgs01Userid=sde
Password=topology
Database=Tshwane_Valuations
Table:Property
and the Following is the Double click event of the datagrid
<br />
Private Sub datagrid1_DblClick()<br />
Dim sSQL As String<br />
Dim rS As New ADODB.Recordset<br />
'Dim con As Object<br />
'Set con = Application.CurrentProject.Connection<br />
iClientId = datagrid1.Columns(0)<br />
sSQL = "SELECT Client.ClientID, Client.ClientCode, Client.Name"<br />
sSQL = sSQL & ",Client.ContactPerson, Client.Address, Client.Telephone"<br />
sSQL = sSQL & ", Client.[E-Mail] as e_mail,CellNo"<br />
sSQL = sSQL & " From Client"<br />
sSQL = sSQL & " Where CLientId = " & iClientId<br />
<br />
If OpenCN Then<br />
rS.Open sSQL, CN, adOpenForwardOnly, adLockReadOnly<br />
If Not rS.EOF Then<br />
cmdClear.Value = True<br />
Me.txtLCLientName = rS("Name")<br />
Me.txtClientCode = rS("ClientCode")<br />
Me.txtContactPerson = rS("ContactPerson")<br />
If Not IsNull(rS("Address")) Then Me.txtAddress = rS("Address")<br />
Me.txtTelephone = rS("Telephone")<br />
If Not IsNull(rS("e_mail")) Then Me.txtEMail = rS("e_mail")<br />
If Not IsNull(rS("CellNo")) Then txtCell = rS("CellNo")<br />
SSTab1.Tab = 1<br />
cmdAdd.Caption = "&Update"<br />
rS.Close<br />
sSQL = "SELECT SysID,ClientId,SyslookupID,Systext1,systext2"<br />
sSQL = sSQL & ", Other, SysVal1, SysVal2, SysVal3, Serial"<br />
sSQL = sSQL & " FROM SysSetting"<br />
sSQL = sSQL & " Where SyslookupID = " & 1<br />
sSQL = sSQL & " And ClientId = " & iClientId<br />
rS.Open sSQL, CN, adOpenDynamic, adLockOptimistic<br />
If Not rS.EOF Then<br />
If rS("Other") = 0 Then<br />
Me.optInActive = True<br />
Else<br />
Me.optActive = True<br />
End If<br />
If rS("SysVal1") = 0 Then<br />
Me.optSingle.Value = True<br />
Else<br />
Me.optMulti.Value = True<br />
End If<br />
If rS("systext2") = "0" Then<br />
Me.cmbcdstiff.ListIndex = 0<br />
Else<br />
Me.cmbcdstiff.ListIndex = 1<br />
End If<br />
txtDate = Format(rS("systext1"), "dd/mm/yyyy")<br />
Me.txtUsers = rS("sysval2")<br />
Me.txtNoKeys = rS("sysVal3")<br />
GetHistory iClientId<br />
End If<br />
End If<br />
End If<br />
rS.Close<br />
Set rS = Nothing<br />
End Sub<br />
Private Sub datagrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)<br />
Dim sSQL As String<br />
Dim rS As New ADODB.Recordset<br />
'Dim con As Object<br />
'Set con = Application.CurrentProject.Connection<br />
If datagrid1.Columns(0) > "" Then<br />
iClientId = datagrid1.Columns(0)<br />
sSQL = "SELECT Client.ClientID, Client.ClientCode, Client.Name"<br />
sSQL = sSQL & ",Client.ContactPerson, Client.Address, Client.Telephone"<br />
sSQL = sSQL & ", Client.[E-Mail] as e_mail,CellNo"<br />
sSQL = sSQL & " From Client"<br />
sSQL = sSQL & " Where CLientId = " & iClientId<br />
<br />
If OpenCN Then<br />
rS.Open sSQL, CN, adOpenForwardOnly, adLockReadOnly<br />
If Not rS.EOF Then<br />
cmdClear.Value = True<br />
Me.txtLCLientName = rS("Name")<br />
Me.txtClientCode = rS("ClientCode")<br />
Me.txtContactPerson = rS("ContactPerson")<br />
If Not IsNull(rS("Address")) Then Me.txtAddress = rS("Address")<br />
If Not IsNull(rS("Telephone")) Then Me.txtTelephone = rS("Telephone")<br />
'MaskEdBox1 = rS("Telephone")<br />
If Not IsNull(rS("e_mail")) Then Me.txtEMail = rS("e_mail")<br />
If Not IsNull(rS("CellNo")) Then txtCell = rS("CellNo")<br />
SSTab1.Tab = 1<br />
cmdAdd.Caption = "&Update"<br />
rS.Close<br />
sSQL = "SELECT SysID,ClientId,SyslookupID,Systext1,systext2"<br />
sSQL = sSQL & ", Other, SysVal1, SysVal2, SysVal3, Serial"<br />
sSQL = sSQL & " FROM SysSetting"<br />
sSQL = sSQL & " Where SyslookupID = " & 1<br />
sSQL = sSQL & " And ClientId = " & iClientId<br />
rS.Open sSQL, CN, adOpenDynamic, adLockOptimistic<br />
If Not rS.EOF Then<br />
If rS("Other") = 0 Then<br />
Me.optInActive = True<br />
Else<br />
Me.optActive = True<br />
End If<br />
If rS("SysVal1") = 0 Then<br />
Me.optSingle.Value = True<br />
Else<br />
Me.optMulti.Value = True<br />
End If<br />
If rS("systext2") = "0" Then<br />
Me.cmbcdstiff.ListIndex = 0<br />
Else<br />
Me.cmbcdstiff.ListIndex = 1<br />
End If<br />
txtDate = Format(rS("systext1"), "dd/mm/yyyy")<br />
Me.txtUsers = rS("sysval2")<br />
Me.txtNoKeys = rS("sysVal3")<br />
GetHistory iClientId<br />
End If<br />
End If<br />
End If<br />
rS.Close<br />
Set rS = Nothing<br />
End If<br />
End Sub<br />
<br />
Private Sub Form_Load()<br />
'cmbsurburb.RowSource = ""<br />
'cmbsurburb.Requery<br />
txtName = ""<br />
txtDate = Format(Date, "dd/mm/yyyy")<br />
Me.FillSearchCombo<br />
SSTab1.Tab = 0<br />
<br />
End Sub<br />
Private Sub Form_Resize()<br />
On Error Resume Next<br />
'This will resize the grid when the form is resized<br />
grdDataGrid.Height = Me.ScaleHeight - 30 - picButtons.Height - picStatBox.Height<br />
'lblStatus.Width = Me.Width - 1500<br />
'cmdNext.Left = lblStatus.Width + 700<br />
'cmdLast.Left = cmdNext.Left + 340<br />
End Sub<br />
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)<br />
If mbEditFlag Or mbAddNewFlag Then Exit Sub<br />
<br />
Select Case KeyCode<br />
Case vbKeyEscape<br />
cmdClose_Click<br />
Case vbKeyEnd<br />
cmdLast_Click<br />
Case vbKeyHome<br />
cmdFirst_Click<br />
Case vbKeyUp, vbKeyPageUp<br />
If Shift = vbCtrlMask Then<br />
cmdFirst_Click<br />
Else<br />
cmdPrevious_Click<br />
End If<br />
Case vbKeyDown, vbKeyPageDown<br />
If Shift = vbCtrlMask Then<br />
cmdLast_Click<br />
Else<br />
cmdNext_Click<br />
End If<br />
End Select<br />
End Sub
Is the Following the right way to Go if i want to save data into the table, because what it does, it update the first record on the table ,on the fields i have supplied.
<br />
Private Sub cmdAdd_Click()<br />
rrs("Num_key") = txtnumkey<br />
rrs("EXTENSION") = txtextension<br />
rrs("Actual_Extent") = txtactualextent<br />
rrs("Lis_key") = txtliskey<br />
rrs("Func_Key") = txtfunckey<br />
rrs("Prop_Category_ID") = txtcategory<br />
rrs("GEOCODE") = txtgeocode<br />
rrs("Add_Date") = txtadddate<br />
rrs("Add_user_ID") = txtadduserid<br />
rrs.Update<br />
cmdNew.Visible = True<br />
cmdUpdate.Visible = True<br />
cmdRefresh.Visible = True<br />
cmdDelete.Visible = True<br />
<br />
End Sub
Lastly this is my SQl Procedure that accept values, inseat the values to be inserted as new record, it update existing first record. in my table there are no update triggers.
<br />
Create Procedure prcInserting (@Num_key varchar(10),@Extension int,@Cell_ID int,<br />
@Actual_Extent float,@Lis_key varchar(50), @Func_key varchar(8),@GeoCode varchar(15))<br />
<br />
with recompile <br />
as<br />
insert into Property(Num_key,Extension,Cell_ID,Actual_Extent,Lis_key,Func_key,Active,Add_date,Add_User_ID,Spatial_ADD_Date,Rateable,Non_Discreet_Valid,Geocode)<br />
values (@Num_key,@Extension,@Cell_ID,@Actual_Extent,@Lis_key, @Func_key,0,getdate(),1,getdate(),0,0,@GeoCode)<br />
<br />
Please Help
Vuyiswa
|
|
|
|
|
Vuyiswamb wrote: Am Sending the who code Please Rearange it for me,
Nope. We don't get paid to do your job, so why should we?
Vuyiswamb wrote: Is the Following the right way to Go if i want to save data into the table, because what it does, it update the first record on the table ,on the fields i have supplied.
Private Sub cmdAdd_Click()
rrs("Num_key") = txtnumkey
rrs("EXTENSION") = txtextension
rrs("Actual_Extent") = txtactualextent
rrs("Lis_key") = txtliskey
rrs("Func_Key") = txtfunckey
rrs("Prop_Category_ID") = txtcategory
rrs("GEOCODE") = txtgeocode
rrs("Add_Date") = txtadddate
rrs("Add_user_ID") = txtadduserid
How many times have we told you "NO" and given you the correct way?
|
|
|
|
|
Hi Everyone:
I have solved the problem of how to bind a DataSet to the BindingNavigator control thanks to those who guided me in the right direction.
I now have another problem that is causing me ulcers.
When I populate the DataSet with data I retrieved from some table. I have no trouble using the move next, move previous, move first and move last buttons on the BindingNavigator control. I can navigate from record to record with no problem.
When I try to add a new record into the dataset using the routine written below; two problems occur. 1 – The auto increment ID number goes from 5(the last record ID in the Dataset) to 7. What happened to 6? 2 – After I add the new record’s data; when I page back through the dataset’s records the new record I just added has the record ID of 7. When I move to the previous record 6 (the one that was skipped) I see the data for the first record in the dataset. Records 5 to 2 seem to be correct, but record 1 is empty.
Code Snippet:
Private Sub New_Bindings(ByVal intOrdinal As Integer, _
ByVal strCode As String, _
ByVal strName As String)
Dim tblBindings As DataTable
tblBindings = MyDataSet.Tables("tblBindings")
Dim drCurrent As DataRow
drCurrent = tblBindings.NewRow
drCurrent("Ordinal") = intOrdinal
drCurrent("BindingCode") = strCode
drCurrent("BindingName") = strName
tblBindings.Rows.Add(drCurrent)
Call Clear_Form()
End Sub
Logic dictates when I add a new record to the dataset it is added at the end of the dataset. This doesn’t seem to be happening. What I plan on doing is after I update the Dataset I will use the DataAdapter to write the changes back to the SQL Sever database, but the dataset looks incorrect, so I won’t commit an update until I’m sure the dataset’s information is correct.
A corollary to this problem is when I try to add records to an empty dataset. I get the DBNull error.
Does anyone know how to add a new record to: 1) an existing dataset, or 2) an empty one?
Thanks,
Quecumber256
|
|
|
|
|
Quecumber256 wrote: Does anyone know how to add a new record to: 1) an existing dataset, or 2) an empty one?
If you add a row to an existing dataset it should work but remember that databases dont necessarily work in first added order.
As for the empty dataset, you need the schema at the least and I believe that is/was a way to FillSchema or something along those lines so that you would have the layout.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
In the situation of a populated dataset I have this:
Retrieved Record 1
Retrieved Record 2
Retrieved Record 3
Retrieved Record 4
Retrieved Record 5
DataSets should append new records at the end of the dataset, like so:
Retrieved Record 1
Retrieved Record 2
Retrieved Record 3
Retrieved Record 4
Retrieved Record 5
Added Record 6
What I am getting is:
Empty Record 1
Retrieved Record 2
Retrieved Record 3
Retrieved Record 4
Retrieved Record 5
Retrieved Record 1
Added Record 7
I don't think the dataset in the above configuration will update my database correctly.
In the situation of an empty dataset I want to add data too. I'm getting this:
Added Record 1
I click the add button on the BindingNavigator control and I get a DbNull exception error. Why does it throw this exception when we have populated the text boxes with data and we are attempting to write them into an empty datset?
Thanks,
Quecumber256
|
|
|
|
|
How are you getting the values from the form and passing them to New_Bindings ?
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
I think I see what is going on. When I open the form I run this procedure:
Private Sub Load_DataSet()
'Connect to the database
Dim cn As SqlConnection = New SqlConnection((My.Settings.PrintsByMe_DevConnectionString))
cn.Open()
'Retrieve the data using a SQL statement
strSQL = "SELECT * FROM [tblBindings];"
Dim cd As New SqlCommand(strSQL, cn)
'Set the database connection for MySqlDataAdapter
daBindings.SelectCommand = cd
'Fill the DataSet and DataSet Schema
daBindings.FillSchema(MyDataSet, SchemaType.Source, "tblBindings")
daBindings.Fill(MyDataSet, "tblBindings")
'Close database connection
cn.Close()
'Set the BindingNavigator's DataSource to the DataSet we created.
bsBindings.DataSource = MyDataSet
'Set the BindingSource Datamember to the table we are using.
bsBindings.DataMember = MyDataSet.Tables(0).TableName()
'Bind form control txtBindingID to the BindingID field
txtBindingID.DataBindings.Add("Text", bsBindings, "BindingID")
'Bind form control txtOrdinal to the Ordinal field
txtOrdinal.DataBindings.Add("Text", bsBindings, "Ordinal")
'Bind form control txtBindingCode to the BindingCode field
txtBindingCode.DataBindings.Add("Text", bsBindings, "BindingCode")
'Bind form control txtBindingName to the BindingName Field
txtBindingName.DataBindings.Add("Text", bsBindings, "BindingName")
End Sub
In a nut shell the code connects to the database, Sets the SqlDataAdapter (daBindings) SelectCommand to the SqlCommand object ‘cd’, Retrieves the table schema and fills in the dataset, and then closes the database connection. Lastly it binds the form controls to separate text boxes on the form so I can use the BindingNavigator to move through the dataset.
When I click on the AddNew button on the BindingNavigator control it fires off this event:
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)
End Sub
The subroutine:
Private Sub New_Bindings(ByVal intOrdinal As Integer, _
ByVal strCode As String, _
ByVal strName As String)
Dim tblBindings As DataTable
tblBindings = MyDataSet.Tables("tblBindings")
Dim drCurrent As DataRow
drCurrent = tblBindings.NewRow
drCurrent("Ordinal") = intOrdinal
drCurrent("BindingCode") = strCode
drCurrent("BindingName") = strName
tblBindings.Rows.Add(drCurrent)
Call Clear_Form()
End Sub
Its suppost to take the data from the text boxes on the form and write it into the dataset. The data record count increases by one when I add a new record, but in the case of an empty dataset the naviation buttons; next, previous, goto first, and goto last are not activated. Therefore, I cannot navigate the dataset.
So how do I refresh the dataset so the navigation buttons become active?
And in the case of a dataset which contains data I get the situation I decribed in my last post. In this case: How do I insure that; 1) the Record counter doesn’t skip from 5 to 7 leaving me an empty record which in turn throws a DbNull exception? 2) The new record is added at the end of the dataset so when I update the database there are no empty records?
This is what I think is wrong. It looks like the textboxes are not being bound to the DataSet.
Thanks,
Quecumber256
|
|
|
|
|