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 4 1354
Seok Bee wrote: 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
I don't have the methods in front of me, but you need to set the
selected index to whichever item you want shown after you do the databind.
Chris
dropdownList.SelectedIndex=0
--
Terry Burns http://TrainingOn.net
"Seok Bee" <se*****@yahoo.com> wrote in message
news:97**********************************@microsof t.com... 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
Thanks Chris and Terry for your replies.
However, my problem is still unable to resolve when I put in the following
statement in my code:
lstAttachments.SelectedIndex=0
When the first time I upload the file into the database, the SELECT
statement is not able to retrieve the 1st file I uploaded. Then I went on to
upload the 2nd file and so on, the SELECT statement able to retrieve and
display the record(s) from 2nd file onward into the listbox control.
So I would like to know, what is the reason being such the way. In another
webform, I used the DataSource and bound it to the listbox control, it able
to view/list all the records into the control box. Please advise...
Thanks in advance.
Regards,
SB
"Terry Burns" wrote: dropdownList.SelectedIndex=0
-- Terry Burns http://TrainingOn.net "Seok Bee" <se*****@yahoo.com> wrote in message news:97**********************************@microsof t.com... 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
I am not seeing anyplace where the ListBox's Index is being checked.
Could it be that it is defaulting to 1 instead of to 0?
When I have had these type of troubles, it seems to be common that I am
not checking the 0 'row' of the List.
Mark Dahl
Seok Bee wrote: 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: John R. |
last post by:
I want to have a listbox that shows a checkbox and a textbox.
I created a user control that has a checkbox and a textbox in it and have
been trying to add it to a listbox but I can't get it to...
|
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...
|
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...
|
by: Janaka |
last post by:
Help! I have two ListBox controls on my web form. The first one gets
populated on entry with values from the DB. I then use JavaScript to copy
options from this ListBox to my second one. (I...
|
by: Dave Sauny |
last post by:
Ok, its a friday, I'm at work and I cant get this to work:
I have 3 listboxes on one tab control page. when i select an item in
listbox1 i want whatever is selected on the other 2 listboxes...
|
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..
|
by: Kevin |
last post by:
I have a few frame controls on my form in my Windows Forms app. I have
a Listbox that stretches over a few of the frame controls but is
invisible until the user click a button. The problem is, when...
|
by: stimul8d |
last post by:
okay; ASP.
I have i listbox inside a user control which is dynamically created on page_init. I check for postback and only populate the datasource if it's false. regardless, i do this
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |