Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
|
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 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 24th, 2010, 07:13 AM
Registered User
 
Join Date: Jun 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post Save Records in listview items to SQL Database

hi,

I was able to save data in sql but i can't save multi rows in listview items,
please can any one help out.the code is give below.



Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Dim intPosition As Integer
Dim strdt As Date
Dim objCommand As SqlCommand = New SqlCommand()
intPosition = objCurrencyManager.Position
objConnection.Open()
strdt = dtp1.Value
objCommand.Connection = objConnection
objCommand.CommandText = "INSERT INTO First_Assortment_Received" & _
"(e_no,part_no,lot_no,date,s_no,p_code,p_than, pwt ) " & _
"VALUES(@e_no,@part_no,@lot_no,@date,@s_no,@p_code ,@p_than,@pwt)"

Dim intMaxID As Integer = lstView.Items.Count
Dim lstStuff As ListViewItem = New ListViewItem()
objCommand.Parameters.AddWithValue("@e_no", txtEntryId.Text)
objCommand.Parameters.AddWithValue("@part_no", txtPartNumber.Text)
objCommand.Parameters.AddWithValue("@lot_no", txtLotNumber.Text)
objCommand.Parameters.AddWithValue("@date", strdt)
objCommand.Parameters.AddWithValue("@s_no", lstView.Items(0).Text)
objCommand.Parameters.AddWithValue("@p_code", lstView.Items(0).SubItems(1).Text)
objCommand.Parameters.AddWithValue("@p_than", lstView.Items(0).SubItems(2).Text)
objCommand.Parameters.AddWithValue("@pwt", lstView.Items(0).SubItems(3).Text)

Try
For i = 1 To intMaxID
objCommand.ExecuteNonQuery()
Next
Catch SqlExceptionErr As SqlException
MessageBox.Show(SqlExceptionErr.Message)
End Try

objConnection.Close()
FillDataSetandView()
BindFields()
objCurrencyManager.Position = intPosition
ShowPosition()
ToolStripStatusLabel1.Text = "Record Added"
GroupBox1.Enabled = False
GroupBox2.Enabled = True
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Change color of items in a ListView eresina Pro VB 6 6 September 15th, 2016 05:09 PM
Save Listview Data to a DataBase ecabralrojas Beginning VB 6 0 June 30th, 2008 10:33 AM
how to update table with listview items Singh591 Pro VB.NET 2002/2003 0 December 30th, 2006 11:13 PM
Listview doesnt change after items are selected. hexOffender VB.NET 2002/2003 Basics 0 December 13th, 2006 12:28 PM
Writting listview items to xml document chandler7272 C# 0 June 12th, 2006 06:01 AM





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