|
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
|
|
|
|
|
Quecumber256 wrote: 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?
If you set the numbering column to the Identity column in the database and let it get that schema it will automatically increment the numbers for you.
Im still not sure what you mean by an empty dataset because as long as you have the schema a new row object is the same whether or not there is data so getting the new row and filling it then adding it to the table should work either way.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
The field BindingID is the Primary key, it is also a counter. In my first experiment when I added a new record using the BindingNavigator the last record number was 5. When I pressed the new record button it said 7 in the dataset. So whenever I clicked the Previous button. The records where completely disjoined because it thought it had 7 records instead of 6.
What happens when you want to retrieve data from a table that has no records? Don't you get a dataset with nothing in it?
I'm making a UI where the user can enter data into the database, so we must account for the situation that the table they are entering in data for might be empty.
I hope this helps clarify the problem.
I need to look
Quecumber256
|
|
|
|
|
Quecumber256 wrote: The field BindingID is the Primary key, it is also a counter. In my first experiment when I added a new record using the BindingNavigator the last record number was 5. When I pressed the new record button it said 7 in the dataset. So whenever I clicked the Previous button. The records where completely disjoined because it thought it had 7 records instead of 6.
This page may help with the navigation.[^]
The dataset will not be nothing if there are no errors accessing the table. As long as it can access the table the column names will be returned but there will be a row count of 0.
You seem to be following the correct procedure for retrieving a new row object and populating the columns then adding it to the table. You might want to try putting hard coded values in there instead of the textboxes just to make sure the row is indeed being added and you can check while debugging by accessing that row ID in the Watch Window.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
I looked at the link you sent to help with the record navigation. All I see is create a new instance of the DataNavigator object. I can't see how this will help me view the record I just added to the dataset. All navigation buttons are disabled.
How can I enable the navigation buttons so I can look at the records before I commit to a database update?
Thanks,
Quecumber256
|
|
|
|
|
The BindingNavigator control will disable the Move Next button under the following run-time circumstances: the BindingSource property is a null reference (Nothing in Visual Basic) or the Position property is greater than or equal to the Count property.
I was referring to the above.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
While I was waiting on your response I did another little experiment.
I went and added two test records into the dataset.
I type in the first record and pressed the Add Record Button on the BindingNavigator control. The current position indicator how says 1 of 1 and the Delete Button on the Navigator is active. No navigation buttons are active.
I added a second record and the current position reads 1 of 2. The record I added above was not recorded into the dataset. The Next and Goto Last Navigation records are now active.
At this point I click the Goto Last Button. I am reading the data for the second record, but it has the ID# of 1 not 2. I click on the Goto First record and the ID# is 0 and only one field contains data.
It looks like the dataset didn't record the data correctly for the first record. I'm going to check the AutoIncrement field in the table on the SQL Server database and see in the seed number is wrong.
Thanks,
Quecumber256
|
|
|
|
|
Hey people,
I am writing a couple of windows forms in vs 2005 (vb).
These forms have quite a few controls on them and the users are going to want an "options" panel where they can , for example , select the background color of a set of buttons (I am simplefying here - bare with me) that appear on the forms.
If this was ASPnet then no problem i could just apply a CSS Style.
Does anyone have any experiance (or code - says he smiling hopefully !) which can apply a dynamic "Style" to a range of windows forms controls (Phew!)
I have heard of visual styles which take precreated XP Themes and apply them but this wont help in this case because I am developing this for people with windows pro 2000 and also I need it to be dynamic.
thanks in advance
Martin Kendrick
Life is a bowl of cherries - go on have a byte
|
|
|
|
|
I thought there was an example of skinning an app here on CP. Basically, what you want to do is write code that sets colors and so on of all your controls, based on a config file.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
yup - in a nutshell- couldnt find the correct search criteria on CP though.
do you where the app skinning example is??
thanks
|
|
|
|
|
Does anyone know how to start the default mail client and paste an image that is in the clipboard to the message body . I have tried SendKey using 3 tabs and control-v but they don't make it to the client. I was hoping to stay away from the API.
Travis Riley
|
|
|
|
|
vb or .net?? in which are u working??
The name is Sandeep
|
|
|
|
|
vb .net 2005
Clipboard.Clear()
Clipboard.SetImage(aChart(cChart).Image.Clone)
Dim emailMessage As New System.Text.StringBuilder
emailMessage.Append("mailto:" & "")
'emailMessage.Append("&subject=" & "")
'emailMessage.Append("&Body=" & aChart(cChart).Image.Clone)
Dim myProcess As New Process
myProcess.StartInfo.FileName = emailMessage.ToString()
myProcess.StartInfo.UseShellExecute = True
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.Start()
' Dim ID = myProcess.SessionId
myProcess.Dispose()
|
|
|
|
|
hi
I m having a class counter in it a function count.in my form load
i inilized my class and start threads for counting now i want to write it threads values (counter values) in text box if console it is working fine.
pls help me
|
|
|
|
|
Hi,
A GUI control can only be updated from the GUI thread.
If you are running a different thread then this must call a function on the GUI thread to perform the update.
you need to use a delegate method and the GUI's InvokeRequired method.
There are a large number of articles on this site that explains this in more detail just search for InvokeRequired
I hope this helps
Martin Kendrick
|
|
|
|
|
|
Hi,
Hi i have some values in datagrid that are generating from database.I want to export those datas to flat file.Plz help me.I m working in ASP.net platform using VB.net
Thnks in advance
Jey
Graviton Solutions.
|
|
|
|
|
This is a question better asked in the ASP.NET forum.
I think you're going to have to provide a link to a page that does the export, which you have to write the code for, then this page should return the export as a normal text file, just like if you were sending back an Excel or Word file. I don't know the specifics myself. That's why I said this question is more appropriate for the ASP.NET forum.
|
|
|
|
|
|
hi i am creating a project in which i am trying to create a handler for a funtion
that funtion skeleton is this
Function execcommand(ByVal commndstr As String)
End Function
i am trying to add handler by this command --- > AddHandler execcommand(), AddressOf execcommand
it shows a error
'AddHandler' or 'RemoveHandler' statement event operand must be a dot-qualified expression or a simple name.
can any one tell why this arises and correct the mistake
thank you
with regards
Balagurunathan.B
|
|
|
|
|
u did not add the event with the handler
|
|
|
|