Dear All vb.net programmers,
I am new to vb.net. I would like to know how to make a progress bar show progress while saving binary data to the database. Please see below for the code I have so far. Please excuse the mess it is need of tiding up when the app is complete
On Error Resume Next
Dim x As Integer
Dim n As Integer
n = 1
Me.ToolStripProgressBar1.Maximum = 100
ToolStripProgressBar1.Step = 1
For x = 0 To n + 1
'see if the user has entered any information
Select Case DocumentTextBox.Text
Case Is = ""
MessageBox.Show("Please browse for the scanned document")
Exit Sub
Case Is = "Please browse for the scanned document"
MessageBox.Show("Please browse for the scanned document")
Exit Sub
End Select
Select Case DocumentIDTextBox.Text
Case Is = ""
MessageBox.Show("Please Enter the Document ID")
Exit Sub
Case Is = "Please enter Document ID"
MessageBox.Show("Please Enter the Document ID")
Exit Sub
End Select
Select Case CustomerTextBox.Text
Case Is = ""
MessageBox.Show("Please enter the Customer Name")
Exit Sub
Case Is = "Please enter the customer name"
MessageBox.Show("Please enter the Customer Name")
Exit Sub
End Select
Select Case DeliveryNumberTextBox.Text
Case Is = ""
MessageBox.Show("Please enter the delivery number")
Exit Sub
Case Is = "Please enter the delivery number"
MessageBox.Show("Please enter the delivery number")
Exit Sub
End Select
'-----------------------------------------------------------------------------------
'check that the document number doesn't exist
' ----- Connect to the database.
Dim theDatabase As New SqlClient.SqlConnection("Server=ws045\sqlexpress;d atabase=dbimages;integrated security=true")
theDatabase.Open()
' ----- Build the basic command.
Dim theCommand As New SqlClient.SqlCommand()
theCommand.CommandType = CommandType.StoredProcedure
theCommand.Connection = theDatabase
theCommand.CommandText = "GetRecordName"
' ----- Add the input parameter. In this case,
' use a test value of 25.
theCommand.Parameters.AddWithValue("@PriKey", Me.DeliveryNumberTextBox.Text)
' ----- Add the output parameter.
Dim outParam As SqlClient.SqlParameter = _
theCommand.Parameters.Add( _
"@nameresult", SqlDbType.NVarChar, 50)
outParam.Direction = ParameterDirection.Output
' ----- Run the stored procedure.
theCommand.ExecuteNonQuery()
' ----- The parameter has been updated for us.
'MsgBox(outParam.Value.ToString)
'If outParam.Value.ToString = Me.DocumentIDTextBox.Text Then
' MessageBox.Show("This record already exists")
'End If
' ----- Clean up.
theCommand = Nothing
theDatabase.Close()
theDatabase.Dispose()
If outParam.Value.ToString = Me.DeliveryNumberTextBox.Text Then
MessageBox.Show("This delivery number already exists in the database", "Incorrect Data Entry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Me.DeliveryNumberTextBox.Select()
Exit Sub
End If
If Me.DocumentIDTextBox.Text.StartsWith("DOC") = False Then
MessageBox.Show("Please enter the full document number starting with DOC", "Data Entry Validation", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.DeliveryNumberTextBox.Select()
Exit Sub
End If
If Me.DocumentIDTextBox.Text.Length < 10 Then
MessageBox.Show("Insufficient characters, there must be 10 characters", "Data Validation", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.DeliveryNumberTextBox.Select()
Exit Sub
End If
If Me.DeliveryNumberTextBox.Text.StartsWith("DEL") = False Then
MessageBox.Show("Delivery number must start with DEL", "Data Validation", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.DeliveryNumberTextBox.Select()
Exit Sub
End If
If Me.DeliveryNumberTextBox.Text.Length < 10 Then
MessageBox.Show("Insufficient characters, there must be 10 characters", "Data Validation", MessageBoxButtons.OK, MessageBoxIcon.Error)
DeliveryNumberTextBox.Select()
Exit Sub
End If
Dim con As New SqlConnection("Server=ws045\sqlexpress;database=db images;integrated security=true")
Dim da As New SqlDataAdapter("SELECT * FROM MyImages", con)
Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
Dim ds As New DataSet()
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim fs As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
'Dim fs As New FileStream("C:\Windows\gone fishing.bmp", FileMode.Open, FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
con.Open()
da.Fill(ds, "MyImages")
UploadDate.Text = Date.Now
Dim myRow As DataRow
myRow = ds.Tables("MyImages").NewRow()
myRow("DocumentNumber") = DocumentIDTextBox.Text
myRow("DeliveryNumber") = DeliveryNumberTextBox.Text
myRow("Customer") = CustomerTextBox.Text
myRow("CurPC") = CurPC.Text
myRow("curuser") = CurUser.Text
myRow("uploadDate") = UploadDate.Text
myRow("imgField") = MyData
ds.Tables("MyImages").Rows.Add(myRow)
da.Update(ds, "MyImages")
fs = Nothing
MyCB = Nothing
ds = Nothing
da = Nothing
con.Close()
con = Nothing
MsgBox("File saved to database")
Kill("C:\Documents and Settings\" & Me.CurUser.Text & "\Desktop\Scanned Document\" & Me.DocumentTextBox.Text & ".pdf")
CustomerTextBox.Text = "Please enter the customer name"
CustomerTextBox.ForeColor = Color.Gray
DocumentIDTextBox.Text = "Please browse for the scanned document"
DocumentIDTextBox.ForeColor = Color.Gray
DocumentTextBox.Text = "Please browse for the scanned document"
DocumentTextBox.ForeColor = Color.Gray
DeliveryNumberTextBox.Text = "Please enter the delivery number"
DeliveryNumberTextBox.ForeColor = Color.Gray
Me.SaveButton.Select()
Next x
ToolStripProgressBar1.PerformStep()
ToolStripProgressBar1.Value = 0