|
Pls HELP me How to print data from datagridview bind on access database. I'm badly need your help. i'm a beginner,
|
|
|
|
|
Research the PrintDocument[^] class.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well my previous post, the await part didn't work, and it operated synchronously.
The main code was suppose to pause and wait for the download to complete and the program to install before moving forward, but just ran to the end.
The previous code I wrote had awaits everywhere in the main code. I really just wanted to call a class that would do the whole thing for me in 1 shot, while the main code waits for the class to finish.
I'm not really sure what this is called in .NET to look up info; perhaps a delegate. And how to adjust my code, and get rid of the await if I have to.
Calling the class, I use to have the await here as well, but then the await kept going up the chain, until finally everything was an await task in the main program - hard to explain.
I didn't think it would be this hard, and I'm having trouble sifting through all the information on the net, and choosing the proper direction / method to take.
Dim localDB_Url_X64 As String = "http://care.dlservice.microsoft.com/dl/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/LocalDB%2064BIT/SqlLocalDB.msi"
Dim localDB_Url_X86 As String = "http://care.dlservice.microsoft.com/dl/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/LocalDB%2032BIT/SqlLocalDB.msi"
Dim desktop_Save As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\SqlLocalDB.msi"
Dim dCB As New download_callback
dCB.httpWebRequest_With_Progress(
New Uri(localDB_Url_X64).ToString,
desktop_Save,
lbl_localDB_Progress,
pbLocalDB
)
My Class - I really just wanted to call this class, and wait for it to finish, but be able to update my progress bar and label. It's a pretty long task, perhaps 10 minutes or so.
The code in the class actually works correctly, and does what I want, just doesn't pause and wait.
Public Class download_callback
Public Async Function httpWebRequest_With_Progress( _
ByVal url As String,
ByVal s As String,
ByVal pLabel As Label,
ByVal pBar As ProgressBar) As Task(Of Integer)
Dim desktop_Save As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\SqlLocalDB.msi"
Dim webClient As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
webClient.AllowAutoRedirect = True
Dim resp = Await (New TaskFactory(Of Net.WebResponse)).StartNew(AddressOf webClient.GetResponse)
pBar.Value = 0
pBar.Maximum = CInt(resp.ContentLength)
Dim rqs = resp.GetResponseStream
Dim bufferSize As Integer = 1 << 16
Dim buffer(bufferSize) As Byte
Dim bytesRecieved As Integer = 0
Dim bytesTotal As Integer = 0
Dim fs As New FileStream(desktop_Save, FileMode.Create)
Do
bytesRecieved = Await (New TaskFactory(Of Integer)).FromAsync(AddressOf rqs.BeginRead, AddressOf rqs.EndRead, buffer, 0, bufferSize, Nothing)
bytesTotal += bytesRecieved
fs.Write(buffer, 0, bytesRecieved)
Dim m_Bytes As String = "Downloading " & (Convert.ToDouble(bytesTotal) / 1048576).ToString("0.00") & " MB" & " / " & (Convert.ToDouble(pBar.Maximum) / 1024 \ 1024).ToString("0.00") & " MB"
pLabel.Text = m_Bytes
pBar.Increment(bytesRecieved)
Loop Until bytesRecieved = 0
If Not fs Is Nothing Then
fs.Close()
fs.Dispose()
End If
If Not rqs Is Nothing Then rqs.Close()
If Not resp Is Nothing Then resp.Close()
frmSetup.lbl_localDB_Title.Text = "Installing Microsoft SQLLocalDB.msi"
pLabel.Text = "Installing SQLLocalDB - Please Wait"
pBar.Value = 0
'Install the Microsoft LocalDB Software
Using localDB As Process = New Process()
Dim localDB_PS As New ProcessStartInfo
localDB_PS.FileName = desktop_Save
localDB.EnableRaisingEvents = True
AddHandler localDB.Exited, AddressOf localDB_Exited
localDB.StartInfo = localDB_PS
localDB.Start()
Do
'Do Nothing, just wait and enjoy the ride
If Not localDB.HasExited Then
pBar.Value = If(pBar.Value < 99, pBar.Value = pBar.Value + 0.1, 0)
End If
Loop While Not localDB.WaitForExit(1200000)
End Using
Return bytesTotal
End Function
Private Sub localDB_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
' Your code goes here
End Sub
End Class
Sorry for all the code, Just wanted to make sure the picture was complete, I rarely post this much code.
|
|
|
|
|
jkirkerx wrote: dCB.httpWebRequest_With_Progress(...)
Your httpWebRequest_With_Progress function returns a Task(Of Integer) . If you want the calling code to pause and wait for the method to complete before continuing, you'll need to Await the returned task.
Await dCB.httpWebRequest_With_Progress(
New Uri(localDB_Url_X64).ToString,
desktop_Save,
lbl_localDB_Progress,
pbLocalDB
)
jkirkerx wrote: Dim resp = Await (New TaskFactory(Of Net.WebResponse)).StartNew(AddressOf webClient.GetResponse)
jkirkerx wrote: bytesRecieved = Await (New TaskFactory(Of Integer)).FromAsync(AddressOf rqs.BeginRead, AddressOf rqs.EndRead, buffer, 0, bufferSize, Nothing)
You shouldn't use the TaskFactory to call synchronous methods on a new background thread:
Should I expose asynchronous wrappers for synchronous methods?[^]
Instead, use the asynchronous methods:
Dim resp = Await webClient.GetResponseAsync()
...
bytesRecieved = Await rqs.ReadAsync(buffer, 0, bufferSize)
Perhaps this walkthrough[^] might help.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I thought that was async.
Thanks for the clarification on that.
Read the articles, It's going to take some more practice and experience to really understand async threading and how to properly implement it.
Now I' wondering if my web browser crawler should run async.
Haven't got rid of the child windows yet, but I will start dumping them 1 at a time, starting with the simplest one first, so I can get the hang of it.
Hey, Thanks for the help, and taking the time to make my skills better on this. I really appreciate it.
Just out of curiosity, why are those child MDI windows so evil?
In the asp.net world, web stuff, I think the update panel and ajax control toolkit is evil, and refuse to use them.
|
|
|
|
|
Alright, I did copy this off the interwebs, sort of stuck on using the await to download a file.
I used the WebClient at first, and was able to use save as to save my file.
On this which actually waits and updates the progress, I think it works, I just can't figure out the save bytes part.
So I have this do loop, not sure if I need to save the buffer in chunks during the loop, or if the buffer has all my bytes, and just do 1 save at the end. The latter produces a bad file, it's missing pieces or something, not complete.
Dim desktop_Save As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\SqlLocalDB.msi"
Dim wc As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
wc.AllowAutoRedirect = True
Dim resp = Await (New TaskFactory(Of Net.WebResponse)).StartNew(AddressOf wc.GetResponse)
p.Value = 0
p.Maximum = CInt(resp.ContentLength)
Dim rqs = resp.GetResponseStream
Dim fs As New FileStream(desktop_Save, FileMode.Create) '// I should move this before write
Dim bufsize As Integer = 1 << 16
Dim buffer(bufsize) As Byte
Dim got As Integer = 0
Dim total As Integer = 0
Do
got = Await (New TaskFactory(Of Integer)).FromAsync _
(AddressOf rqs.BeginRead, AddressOf rqs.EndRead, buffer, 0, bufsize, Nothing)
total += got
Dim m_Bytes As String = _
"Downloading " & (Convert.ToDouble(total) / 1048576).ToString("0.00") & _
" MB" & " / " & (Convert.ToDouble(p.Maximum) / 1024 \ 1024).ToString("0.00") & " MB"
l.Text = m_Bytes
p.Increment(got)
Loop Until got = 0
fs.Write(buffer, 0, bufsize) '
fs.Close()
rqs.Close()
resp.Close()
|
|
|
|
|
With a fresh mind in the morning,
I had to write the buffer during the loop, and used bytes received as the count in the filesystem.write.
So now I get a clean write, and the file works correctly as well.
Dim bufferSize As Integer = 1 << 16
Dim buffer(bufferSize) As Byte
Dim bytesRecieved As Integer = 0
Dim bytesTotal As Integer = 0
Dim fs As New FileStream(desktop_Save, FileMode.Create)
Do
bytesRecieved = Await (New TaskFactory(Of Integer)).FromAsync(AddressOf rqs.BeginRead, _
AddressOf rqs.EndRead, buffer, 0, bufferSize, Nothing)
bytesTotal += bytesRecieved
fs.Write(buffer, 0, bytesRecieved)
Dim m_Bytes As String = "Downloading " & (Convert.ToDouble(bytesTotal) / 1048576).ToString("0.00") & " MB" & _
" / " & (Convert.ToDouble(pBar.Maximum) / 1024 \ 1024).ToString("0.00") & " MB"
pLabel.Text = m_Bytes
pBar.Increment(bytesRecieved)
Loop Until bytesRecieved = 0
If Not fs Is Nothing Then
fs.Close()
fs.Dispose()
End If
|
|
|
|
|
Hi Friends,
I need to calculate my tester's ideal time and generating a report through Visual Basic 6.0..
So, Select the MSflexgrid for better presentation..
I did fetching the file name and its created date from the defined directory to MSFlexgrid..
Now, i need to calculate the time gap between each and every file in another column of the MSFlexgrid..
So, Kindly help me on this regard as soon as possible..
Thanks,
Muraliraj
|
|
|
|
|
|
Hello !
I have a gridview bound to entity.
When I modify an existing value in a row , and after call Savechanges , everything is saved to database.
If I add a new row , or Delete an existing row from gridview , and after call savechanges , these changes are not saved to database.
What can I do ?
Thank you !
|
|
|
|
|
dilkonika wrote: What can I do ?
Debug your code. What else are you going to do?
Look at what you posted and think about what you supplied to us to help you solve this problem. NOTHING. We can't see your screen, your hard drive, see your code or read your mind. Hell, we don't even what kind of app this is! Is it Windows Forms? WPF? ASP.NET or MVC? or what?
Without seeing your code that loads the data and binds it to the grid and the code that saves it, it's impossible for anyone to tell you what you did wrong.
|
|
|
|
|
Hello !
I'm using VB.net 2013.
This is my code to load data in gridview :
Datagridview1.Datasource=(From t in context.orders select t).Tolist
Thank you !
|
|
|
|
|
...sigh....
You're not thinking. WHAT ELSE DO WE NEED TO SEE THAT MAY HAVE A PROBLEM WHEN YOU GO TO SAVE THE DATA??
|
|
|
|
|
I have this dialog, I just want it to stay inside the mdi parent and be centered.
But I get this error message, I don't understand the top level vs mdi parent part.
credDialog = New dialog_credentials(True)
credDialog.TopLevel = True
credDialog.MdiParent = Me
credDialog.StartPosition = FormStartPosition.Manual
credDialog.Left = (Me.Width - credDialog.Width) / 2
credDialog.Top = (Me.Height - credDialog.Height) / 2 - 100
If (credDialog.ShowDialog(Me) = DialogResult.OK) Then
Additional information: Form that is not a top-level form cannot be displayed as a modal dialog box. Remove the form from any parent form before calling showDialog.
I know it's straight forward, remove the mdiparent.
|
|
|
|
|
I'll just stick with a regular dialog, it works fine.
|
|
|
|
|
Why are you even using MDI?
Your code sample seems to say that you don't know what it was designed for and are trying to force it to do something it's not designed to do.
|
|
|
|
|
It was an option, so I took it.
But now I know better.
Not sure why it's there for a dialog.
I'll do some research tonight on it.
|
|
|
|
|
Because a Dialog is nothing but a specialized Form?
Seriously, why are you even using MDI?
|
|
|
|
|
I made a windows app that basically is a crawler for a friend. it crawls a dealer website and collect all the items, prices and stock.
The main window is a MDI parent.
The first form, MDI, is the main crawler that does the data acquisition. has a web browser
The 2nd form, MDI, allows you to work with the data collected. has a listview
I have 5 dialogs,
About
Progress
UserInfo
Preferences
Download LocalDB
Program Intialization.
In hindsight, I really don't need the first form, so I'm going to try and move the functionality to the main Form.
I'll admin, I'm not an expert in windows program design, but decent at it.
I remember now, I run the progress dialog with MDI parent, so I thought I could do the same.
When I ran the UserInfo dialog with MDI parent, I wasn't able to get the values from the textbox in the dialog.
I don't have an answer to the question
|
|
|
|
|
OK, MDI stands for Multiple Document Inteface.
Imagine have a child window that is a Notepad like text editor. The MDI interface was designed to have multiple copies of that child window in the MdiClient area of the parent form, allowing you to edit multiple files at the same time.
MDI is an outdated concept that Microsoft doesn't even support/use any more.
What you're describing about your app doesn't lend itself to MDI at all, and frankly, I think hinders your UI by using it.
|
|
|
|
|
Just change the forms to non MDI?
And then work on the UI and make it more modern?
|
|
|
|
|
|
OK, I think I get it now.
I have a question
Take Microsoft Work 2013 for instance, that latest one.
The program opens, and you get that no window looking thing, you pick a task, and you get
something that resembles a window.
Click file, and you get that smooth look again.
What is that smooth look?
Is it a panel?, or like a smooth look object?
Seriously, I have some good ideas now for a UI.
|
|
|
|
|
I have no idea what you're talking about and I staring at Word 2013.
|
|
|
|
|
i should of taken a picture of it or something.
Anyways, you motivated me to make a huge UI change or upgrade, and I'm very pleased with how it looks and operates now. WOW what a difference.
I tried using just panels for different layouts, and dock filling them when needed.
But ended up going back to the
frm_Main - MDI Parent Container
frm_View - MDI CHild
frm_Aquire - MDI Child
The rest is just dialogs.
I really don't need the child windows, I just need display containers that go full dock inside the parent window, but I have no clue how to go about it.
This is only my 3rd windows app in the last 4 years. So my UI and design knowledge is really out dated. I can write the code very well for function, but my UI program design is very 1996, which is when I wrote my last production windows app.
I have to get this project out this week, as a prototype for a future project next year.
But I will go back and remove each child window in the project after submitting the prototype.
|
|
|
|
|