473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Listbox controls

Dear Experts,

I am having 1 listbox control in my web form and trying to retrieve the
items and load into it. I want to list out those uploaded files into the
database and list out in the listbox control. My code is as follow:

-------------------------------------------
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnUpload.Click
litMsgBox.Text = ""
If FileUpload1.HasFile Then
'Upload Attachment to Server
If Not FileUpload1.FileContent Is Nothing Then
'perform validation logic before updating the database -
i.e. if file size is
With FileUpload1.FileContent
Dim abyContent(CType(.Length, Integer)) As Byte
'allocate buffer for file data
.Read(abyContent, 0, .Length)

'Update the attach filename into database
InsertFile(FileUpload1.FileName, abyContent)

'Update the attach filename into server folder
SaveFile(FileUpload1.FileName)

'btnUpload.Enabled = False
'btnDelete.Visible = True
'strAllAttachFiles = strAllAttachFiles &
FileUpload1.FileName & ","

'txtRequest.Text = strAllAttachFiles
End With
End If

Else
strMsgBox = "<script language='Javascript'>alert(""No File to be
uploaded"")"
strMsgBox = strMsgBox & Chr(60) & "/script>"
litMsgBox.Text = strMsgBox
End If
LoadAttachments(intRequestID)

End Sub

Private Sub InsertFile(ByVal strFilename As String, ByVal abyContent As
Byte())
'Dim oConnection As New OleDbConnection(strConnectionString)
'Dim intRequestID As Integer
Try
DatabaseConnection()
intRequestID = Int(txtReqNo.Text)
Dim strFileUploadQuery As String = "INSERT INTO Attachments
(Attachments, FileContent, RequestID) VALUES (?,?," & intRequestID & ")"
Dim oCommand As New OleDbCommand(strFileUploadQuery, dbConnection)
Dim oParameter As OleDbParameter = Nothing
oParameter = New OleDbParameter("?", OleDbType.VarChar)
oParameter.Value = strFilename
oParameter.Direction = ParameterDirection.Input
oCommand.Parameters.Add(oParameter)

oParameter = New OleDbParameter("?", OleDbType.VarBinary)
oParameter.Value = abyContent
oParameter.Direction = ParameterDirection.Input
oCommand.Parameters.Add(oParameter)

oCommand.CommandTimeout = 120
oCommand.CommandType = CommandType.Text

oCommand.ExecuteNonQuery()
Catch ex As Exception
Throw ex

Finally
DatabaseDisconnection()
LoadAttachments(intRequestID)
End Try
End Sub

Public Sub LoadAttachments(ByVal intReqID As Integer)
Try
DatabaseConnection()
Dim strSQLFileAttach As String = "SELECT * FROM Attachments
WHERE RequestID = " & intReqID

Dim FileAttachCommand As New
Data.OleDb.OleDbCommand(strSQLFileAttach, dbConnection)
Dim FileAttachReader As Data.OleDb.OleDbDataReader =
FileAttachCommand.ExecuteReader()
lstAttachments.Items.Clear()
FileAttachReader.Read()

lstAttachments.DataValueField = "AttachmentID"
lstAttachments.DataTextField = "Attachments"
lstAttachments.DataSource = FileAttachReader
lstAttachments.DataBind()

FileAttachReader.Close()

Catch ex As Exception
TextBox1.Text = ex.Message
Finally
DatabaseDisconnection()
End Try

End Sub

--------------------------------------------------

My problem is when I retrieve the data, some how the 1st row of the data
does not appear. May I know where and how to get this problem solve?

Many thanks in advance.

Regards,
SB
Feb 26 '06 #1
0 828

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
5
by: lukasmazur | last post by:
Hi I have a problem with using listBox1. I have a two forms form1 and form2. In form1 are controls listBox1, textBox1 and button witch creating object of class Form2. In class Form2 I create a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.