Wrox Programmer Forums
|
BOOK: Beginning Microsoft Visual Basic 2010
This is the forum to discuss the Wrox book Beginning Visual Basic 2010 by Thearon Willis, Bryan Newsome; ISBN: 9780470502228
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Microsoft Visual Basic 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2011, 03:38 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default BindingExample

Hi All,

I am getting problem in BindiningExample of chapter 16 Page 509

Sort and currency manager is not working in this example.

sorting is not occuring and when i use currencymanager to show the next recored its also not working .

Can any one help me where i miss some thing or additionallly something is needed to add in this code.

Thanks

Kapil
 
Old July 5th, 2011, 12:28 AM
Wrox Author
 
Join Date: Mar 2006
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Hi Kapil,

Can you paste your code here? Also, you can download a working example of the code to see if you missed anything while comparing it to yours from wrox. The link is at the top of this page.

Bryan
 
Old July 5th, 2011, 11:46 PM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Bryan,

Thanks for replying.

I am using the same code as written in book . also i have downloaded the bindingexample code from site . I am sorry to say may be i miss some thing. but its also not working. Null exception error comes at "Cm.Position +=1".
I am strucked from 3 weeks on same page of the book. Plz guide.
Here is my code.


'import Data and Sql client namespaces
Imports System.Data
Imports System.Data.SqlClient


Public Class Form1
'Global Declarations
Dim con As New SqlConnection("Data Source=KRISHNA-PC;Initial Catalog=Demo Database NAV (6-0);Integrated Security = True")
Dim da As New SqlDataAdapter("Select * from [CRONUS India Ltd_$Vendor]", con)
Dim ds As DataSet
Dim dv As DataView
Dim cm As CurrencyManager
Private Sub FillDataSetAndView()
'Initialize a new instance of dataset
ds = New DataSet()
'Fill dataset with data
da.Fill(ds, "[CRONUS India Ltd_$Vendor]")
'Set Dataview
'dv = New DataView(ds.Tables(0))
dv = New DataView(ds.Tables(0))
'Set cureency manager
'cm = CType(Me.BindingContext(dv), CurrencyManager)
cm = CType(Me.BindingContext(dv), CurrencyManager)
End Sub
Private Sub BindFields()
'clear any previous binding
txtAdd.DataBindings.Clear()
txtcity.DataBindings.Clear()
txtname.DataBindings.Clear()
txtNo.DataBindings.Clear()
'Add New Bindings
txtNo.DataBindings.Add("Text", ds, "[CRONUS India Ltd_$Vendor].No_")
txtname.DataBindings.Add("Text", ds, "[CRONUS India Ltd_$Vendor].Name")
txtAdd.DataBindings.Add("Text", ds, "[CRONUS India Ltd_$Vendor].Address")
txtcity.DataBindings.Add("Text", ds, "[CRONUS India Ltd_$Vendor].City")
'Display a ready status
ToolStripStatusLabel1.Text = "Ready"
End Sub
Private Sub ShowPosition()
'Display the current record and no of records
txtrecposition.Text = cm.Position + 1 & "of " & cm.Count
End Sub

Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup

End Sub

Private Sub StatusStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs ) Handles StatusStrip1.ItemClicked

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add Item to combobox
cboField.Items.Add("No.")
cboField.Items.Add("Name")
cboField.Items.Add("Add")
cboField.Items.Add("City")
'Make the first item selected
cboField.SelectedIndex = 0
'Fill the dataset and bind the field
FillDataSetAndView()
BindFields()
'Show the current record position
ShowPosition()
End Sub

Private Sub cboField_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboField.SelectedIndexChanged

End Sub

Private Sub btnmovefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmovefirst.Click
cm.Position = 0
Me.BindingContext(ds, "[CRONUS India Ltd_$Vendor]").Position = 0
ShowPosition()
End Sub

Private Sub btnmovepre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmovepre.Click
cm.Position -= 1
Me.BindingContext(ds, "[CRONUS India Ltd_$Vendor]").Position -= 1
ShowPosition()
End Sub

Private Sub btnmovenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmovenext.Click
cm.Position += 1
'Me.BindingContext(ds, "[CRONUS India Ltd_$Vendor]").Position += 1
ShowPosition()
End Sub

Private Sub btnmovelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmovelast.Click
cm.Position = cm.Count - 1
Me.BindingContext(ds, "[CRONUS India Ltd_$Vendor]").Position = Me.BindingContext(ds, "[CRONUS India Ltd_$Vendor]").Count - 1
ShowPosition()
End Sub

Private Sub btnSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSort.Click
'Determine the appropriate selected item and sort property of dataview
Select Case cboField.SelectedIndex
Case 0 'No.
dv.Sort = "No_"
Case 1 'Name
dv.Sort = "Name"
Case 2 'Add
dv.Sort = "Add"
Case 3 'City
dv.Sort = "City"
End Select
'Call the click event for move first button
btnmovefirst_Click(Nothing, Nothing)
'Display a messate that record has been sorted
ToolStripStatusLabel1.Text = "Records has been Sorted"
End Sub

Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
'txtNo.Text = " "
'txtname.Text = " "
'txtAdd.Text = " "
'txtcity.Text = " "
'declare local varibale
'Dim intposition As Integer, intmaxid As Integer
'Dim strid As String
'Dim objcommand As New SqlCommand
'save the current record position
'intposition = cm.Position
'createa new sqlcommand object
'Dim maxidcommand As SqlCommand = New SqlCommand ("Select MAX(No_) AS MAXID " &
End Sub
End Class

Regards

Kapil
 
Old July 8th, 2011, 04:05 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Any update

Hi All,

Any update......
 
Old July 9th, 2011, 04:30 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi

Hi All,

My issue has been resolved and its working fine when bindingwith data view i was useing table name with firld name that why dataview was not working properly.

Now i am strucked at new point where i am inserting records in table ..i am inserting record in primary key of table and error handler is giving me error for last field of table that its can not be null so insert failed.
Last firld is not the part of primary key.
Here is the code.

Finally set the new value with setting new sqlcommand
objcommand.Connection = con
objcommand.CommandText = "INSERT INTO [CRONUS India Ltd_$Vendor] (No_) VALUES (@No_)"

objcommand.Parameters.AddWithValue("@No_", "abc")

Error is ..
---------------------------

---------------------------
Cannot insert the value NULL into column 'Composition', table 'Demo Database NAV (6-0).dbo.CRONUS India Ltd_$Vendor'; column does not allow nulls. INSERT fails.

The statement has been terminated.
---------------------------
OK
---------------------------

Please suggest.

Thanks
Kapil
 
Old July 21st, 2011, 10:53 PM
Wrox Author
 
Join Date: Mar 2006
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Your table has more columns. One 'Composition' is required and you are not inserted it so you insert fails. You need to insert a value into this column as well.
 
Old July 21st, 2011, 11:26 PM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert issue...

Hi,

yes its a field in table and its attribute is not null in sql so while inserting for two field only the INSERT command serach for whole table that y give error for composition field.


If composition is not a part of primary key..then is there any way by which we can skip this not null property of sql table.

Please Suggest

Kapil
 
Old July 21st, 2011, 11:44 PM
Wrox Author
 
Join Date: Mar 2006
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

No, if it is set to not null then you must insert data into it. If you can change the table, you can give the column a defult value possibly so when you don't insert a value it will have a default. If you can do that, just insert a default value. Bryan
 
Old July 24th, 2011, 11:59 AM
Registered User
 
Join Date: Jun 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi

ya ..i also concluded the same thing....that anyhow the data must go in it..

Thanks Bryan
 
Old July 24th, 2011, 05:42 PM
Wrox Author
 
Join Date: Mar 2006
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Good luck. Bryan





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16 - Oracle Client - BindingExample andy_study BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 December 3rd, 2004 06:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.