Click here to Skip to main content
15,901,205 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Read what i asked? Pin
kantipudi21-May-07 19:48
kantipudi21-May-07 19:48 
QuestionHelp me make this code to Point to SQl Server that Access localy Pin
Vimalsoft(Pty) Ltd18-May-07 3:39
professionalVimalsoft(Pty) Ltd18-May-07 3:39 
AnswerRe: Help me make this code to Point to SQl Server that Access localy Pin
Dave Kreskowiak18-May-07 4:20
mveDave Kreskowiak18-May-07 4:20 
QuestionProblems add a new record to a DataSet using the BindingNavigator Control Pin
Quecumber25618-May-07 3:11
Quecumber25618-May-07 3:11 
AnswerRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Marcus J. Smith18-May-07 4:36
professionalMarcus J. Smith18-May-07 4:36 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Quecumber25618-May-07 5:13
Quecumber25618-May-07 5:13 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Marcus J. Smith18-May-07 5:32
professionalMarcus J. Smith18-May-07 5:32 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Quecumber25618-May-07 6:22
Quecumber25618-May-07 6:22 
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
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Marcus J. Smith18-May-07 7:20
professionalMarcus J. Smith18-May-07 7:20 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Quecumber25618-May-07 7:34
Quecumber25618-May-07 7:34 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Marcus J. Smith18-May-07 8:10
professionalMarcus J. Smith18-May-07 8:10 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Quecumber25618-May-07 8:47
Quecumber25618-May-07 8:47 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Marcus J. Smith18-May-07 9:53
professionalMarcus J. Smith18-May-07 9:53 
GeneralRe: Problems add a new record to a DataSet using the BindingNavigator Control Pin
Quecumber25618-May-07 10:14
Quecumber25618-May-07 10:14 
Questioncreating stles for windows form controls Pin
MartyK200718-May-07 2:26
MartyK200718-May-07 2:26 
AnswerRe: creating stles for windows form controls Pin
Christian Graus18-May-07 3:04
protectorChristian Graus18-May-07 3:04 
GeneralRe: creating stles for windows form controls Pin
MartyK200718-May-07 3:06
MartyK200718-May-07 3:06 
QuestionHow to paste to the default mail client Pin
triley125818-May-07 1:08
triley125818-May-07 1:08 
AnswerRe: How to paste to the default mail client Pin
Xandip18-May-07 1:58
Xandip18-May-07 1:58 
GeneralRe: How to paste to the default mail client Pin
triley125818-May-07 3:43
triley125818-May-07 3:43 
Questionthreads Problem Pin
psiva198418-May-07 1:00
psiva198418-May-07 1:00 
AnswerRe: threads Problem Pin
MartyK200718-May-07 2:34
MartyK200718-May-07 2:34 
GeneralRe: threads Problem Pin
psiva198418-May-07 18:55
psiva198418-May-07 18:55 
QuestionExport data from grid to flat file Pin
jeya krishnan.v18-May-07 0:39
jeya krishnan.v18-May-07 0:39 
AnswerRe: Export data from grid to flat file Pin
Dave Kreskowiak18-May-07 4:11
mveDave Kreskowiak18-May-07 4:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.