For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
I'm using vb.net 2017 with EF 6 and Sql Server 2008 R2.
I'm writing a code to read data from an excel file and after to save on the database.The excel file will have very large number of records. ( maybe 50.000 or even more ).
When is better to call context.savechanges :
- After adding each record
- After adding a number of n records ( !! If yes , what is the best number )
- After adding all records
Should all the records in the Excel sheet be treated individually? Should they be treated as one unit? What happens if you're app crashed or is otherwise interrupted during the write to the database? What do you track, if anything, to recover? Do you start over and rewrite the records you already wrote in the database? Do you try to resume from the last successfully written record?
You COULD save after every record. It'll slow things down but you'll get a verified write on each and every one.
What's the "best" number of records? It's impossible for anyone to say. Again, it depends on a ton of factors. There is no "one value" to rule them all.
You COULD save after the entire set is created. That will result in a long save operation that'll return a single error if there is a problem with any record in the operation.
It's impossible for anyone, other than yourself, to answer your question.
The problem is that or i should write all the records from Excel to database , or if a single record has problems no records will be saved.
I will make this proces in 2 steps :
1. I read one by one all the records from Excel and test them if they are correct and can be saved to database.If one of the record is ok , I add it on entity. If one record has problems , the context is disposed , and the user has to correct the problems and to start testing again the excel data.
2.If the test procedure goes without error , I call savechanges.
So , i call savechanges after all objects are added to entity.
But i don't know if this is safe , so i want your opinion and i should changes the code that I've described before.
I have an application that runs access database with about 50 tables but i want to search all the tables with Refno since the tables all have it, and i don't want to use the inner join because if it do and some tables don't have data it wont populate, so how do i search all the tables and display on crystal report the code i use for the search is below
Dim sFmt1 As String = "/MyCalendar/Appointments/Appointment[@CompanyKey='Mr. Key']"
Dim sFmt2 as string = "/MyCalendar/Appointments/Appointment[@CompanyKey='Mr. Key' and Date='11/11/2018 12:00 AM']"
'Dim sFmt2 as string = "/MyCalendar/Appointments/Appointment[@CompanyKey='Mr. Key'][Date='11/11/2018 12:00 AM']"
Dim node As XmlNode = Me._XmlDoc.DocumentElement.SelectSingleNode(sFmt2)
If IsNothing(node) = True Then
Debug.WriteLine("Failed - " + sFmt)
Debug.WriteLine("Found - " + sFmt)
//This code is working but i want is vice versa of the sample output plus current year...
Public Sub incrPR()
Dim curValue As Integer
Dim result As String
Dim s As String = "PR"
Dim yr As String = Now.Year.ToString()
Using con As SqlConnection = New SqlConnection(ConString)
Dim cmd = New SqlCommand("Select MAX(SpecialOrderNo) FROM SpecialOrder", con)
result = cmd.ExecuteScalar().ToString()
If String.IsNullOrEmpty(result) Then
result = "PR000"
result = result.Substring(3)
curValue = curValue + 1
result = s + curValue.ToString("D3")
txtno.Text = result
//Sample output: PR001, PR002//Question: How to Increment Number with current year and Characters? //Expected sample output: 001-2018-PR//Thank you
curValue is the number (if I read that right), so you just need to construct your string from that followed by the year followed by "PR". Each field separated by the '-' character. What is the problem with doing that?