Question about Microsoft Visual Basic 6.0 for PC

1 Answer

Inserting records into sql server using VB

.ExternalClass .EC_hmmessage P {padding:0px;} .ExternalClass body.EC_hmmessage {font-size:10pt;font-family:Verdana;} hi

i've added new item called service- based database. after that, i've created doctor table, course table, exam table, and an empty table called exam_report to allow program selects randomly from the other tables.

how it works:
first the user will get a form with many buttons: courses, doctors, exams, and exam report.
second if the user click over exam report, a new form will appear with many columns. this form should has exam course - exam day - exam time - 3 doctors name who will observe the students.

behind code:
the doctors shouldn't be the instructors of the course - the doctor has no appoinment in this day - the doctor has no hloiday and so on..

okay my code is the following :

Public Class Form6
Dim j, a As Integer
Dim d, f, h As Integer
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ta_ExamReport As Database1DataSet1TableAdapters.exam_reportTableAdapter

Dim ta_All_Courses As Database1DataSet1TableAdapters.courseTableAdapter = New Database1DataSet1TableAdapters.courseTableAdapter
Dim All_Courses As Database1DataSet1.courseDataTable = New Database1DataSet1.courseDataTable

Dim ta_All_Doctors As Database1DataSet1TableAdapters.doctorTableAdapter = New Database1DataSet1TableAdapters.doctorTableAdapter
Dim All_Doctors As Database1DataSet1.doctorDataTable = New Database1DataSet1.doctorDataTable

Dim ta_All_Exams As Database1DataSet1TableAdapters.examTableAdapter = New Database1DataSet1TableAdapters.examTableAdapter
Dim All_Exams As Database1DataSet1.examDataTable = New Database1DataSet1.examDataTable

d = 0
f = 0
h = 0

ta_ExamReport = New Database1DataSet1TableAdapters.exam_reportTableAdapter

Dim check3times As Integer = 3
For Me.a = 0 To All_Exams.Rows.Count() - 1
For Me.j = 0 To All_Doctors.Rows.Count() - 1

If (All_Doctors(j)("InvigNum") > 0 And All_Doctors(j)("DRID") <> All_Exams(a)("DRID") And All_Doctors(j)("holidays") <> All_Exams(a)("EXday") And All_Doctors(j)("appt_days") <> All_Exams(a)("EXday")) Then

If (h = 1 And f = 1 And d = 0) Then
All_Doctors(j)("InvigNum") = ta_All_Doctors.UpdateInvigNumAuto()
d = 1
End If
If (h = 1 And f = 0 And d = 0) Then
All_Doctors(j)("InvigNum") = ta_All_Doctors.UpdateInvigNumAuto()
f = 1
End If
If (h = 0 And f = 0 And d = 0) Then
ta_ExamReport.InsertIntoExamReport(All_Exams(a)("EXday"), All_Exams(a)("CID"), All_Doctors(j)("Dname"), All_Doctors(j)("Dname"), All_Doctors(j)("Dname"))
All_Doctors(j)("InvigNum") = ta_All_Doctors.UpdateInvigNumAuto()
h = 1
End If
If (h = 1 And f = 1 And d = 1) Then
h = 0
d = 0
f = 0
End If
End If
j = j + 1
a = a + 1

End Sub

now, this is free from errors, but it didn't get inside the big if statement >...... WHY??

Posted by on

1 Answer

  • Level 3:

    An expert who has achieved level 3 by getting 1000 points


    An expert that got 10 achievements.


    An expert that got 5 achievements.

    Vice President:

    An expert whose answer got voted for 100 times.

  • Master
  • 489 Answers

It didn't enter the big if statement because all of the conditions to enter the loop were not met. You will need to set a breakpoint on the If statement and look at the values to find out why it falls short of the criteria.

Also, instead of incrementing the loop variables immediately before the Next statement, you could simply include a Step 2 modifier in the For statement to check every other row in the tables. You should not manually modify a counter in a For loop. You have class-level variables that appear to be used only inside of a Sub (that is where they should be declared unless they are used in another function in the class). You should be giving variables meaningful names and types. The variables d, h, and f are declared as integers, but treated as booleans and their names give no idication of their use in the code. And last (for now), the check3times varialbe is declared but never used.

Posted on May 26, 2009

1 Suggested Answer

  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%


Complete. Click "Add" to insert your video. Add



Related Questions:

5 Answers

How do I recover data from .mdf file

Detach you database. Overwrite the mdf and ldf files you've restored from your backup with your files from the D: drive. Reattach the database.
There is no guarantee that this will work or if it works, that your database is in a state where you can continue to work with.
If that doesn't work then there is an option to try to restore database using SQL Server Recovery Toolbox. It is a powerful tool for data recovery. They have a demo version. So you can check it works in your situation or not.

Jan 19, 2016 | Microsoft SQL Server 2008 Enterprise Full...

5 Answers

Import damaged SQL MDF file

I would like to suggest you to use of MDF Repair Kit. An exciting new product from Repair Kit, this MS SQL MDF repair tool is an absolutely indispensable tool for anyone who wants to know how to repair MDF files in minutes. The program is based on a powerful analysis core and uses a convenient wizard-driven UI.

For more:

Apr 25, 2015 | Microsoft SQL Server 2005 Enterprise...

3 Answers

How to fix mySQL corrupt databases?

you should follow two steps:

Create an appropriately named database on the target machine
Load the file using the mysql command:
$ mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]
Have a look how you can restore your tut_backup.sql file to the Tutorials database.
$ mysql -u root -p Tutorials < tut_backup.sql
To restore compressed backup files you can do the following:
gunzip < [backupfile.sql.gz] ' mysql -u [uname] -p[pass] [dbname]
If you need to restore a database that already exists, you'll need to use mysqlimport
command. The syntax for mysqlimport is as follows:
mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]

Or make use of Repair Toolbox for MySQL

Demo version is here-:

Feb 08, 2015 | Microsoft SQL Server 2000 Standard Edition...

2 Answers

Printing syntax

'declare the variables
Dim Connection
Dim ConnString
Dim Recordset

'define the connection string, specify database driver
ConnString="DRIVER={SQL Server};SERVER=yourServername;UID=yourUsername;" & _

'declare the SQL statement that will query the database

'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

'Open the connection to the database

Connection.Open ConnString

'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection

'first of all determine whether there are any records
If Recordset.EOF Then
Response.Write("No records returned.")
'if there are records then loop through the fields
Do While NOT Recordset.Eof
Response.write Recordset("FIRST_FIELD_NAME")
Response.write Recordset("SECOND_FIELD_NAME")
Response.write Recordset("THIRD_FIELD_NAME")
Response.write "<br>"
End If

'close the connection and recordset objects to free up resources
Set Recordset=nothing
Set Connection=nothing

May 16, 2009 | Microsoft Windows Vista Ultimate Edition

1 Answer

I am trying to connect to a SQL Server 2005 DB from Visual Studio

You must create an ODBC connection to your SQL database in the Windows Control Panel. Than you can call your ODBC connection via Visual Studio 2005. You can also create a DSN in Visual Studio 2005 and reference in that way. You will not be able to connect to an MDF but instead you have to connect to the SQL Server Service. Of course the username you use to connect must have access that will be created on the SQL server.

Apr 13, 2009 | Microsoft SQL Server 2005 Standard Edition

4 Answers

How get sql data backup

there is facility in enterprise manager to take back of database!

Feb 04, 2009 | Keystone Active Server Pages (ASP)/Visual...

4 Answers

Restoring files from the database

I suggest you use the Enterprise manager (gui tool to manage SQL).
Restoring a single table is not an option.
You can however restore a file or filegroup.
Make sure to backup before you start and NOT to restore database to its original name or original file location, to avoid acidents.
Normally you will have databases with only 2 files: the data at its Primary file group, and log file.
You may wish to create a new file group and move tables to the new group by recreating them there and exporting data from old table to new table. Then recreate indexes. This may prove to be complex as all tables and indexes have unique names and can't coexist with exact duplicate of them.

oh yea..... did I say backup?
well just in case backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup backup
but dont overwrite that backup

Feb 11, 2008 | Microsoft SQL Server 2000 Standard Edition...

1 Answer

SQL Server 2000

An easy way to transfer objects (tables, user defined functions, stored procedures, etc.) is to use Enterprise Manager's "Generate SQL" feature. Use this process at your own risk. Doing it wrong could mess up your existing database.

1. In Enterprise Manager, right-click on the old database and choose "All Tasks" then "Generate SQL Script".
2. In the dialog that comes up, click "Show All" then select the checkboxes for "all stored procedures" and "all user defined functions". (You might also want to check some other boxes, depending on your exact situation.)
3. Click the "generate" button and save the script that it creates.
4. Run the script in the NEW database.

If you run the script in your OLD database, it may destroy your objects, and that would be very bad. Make sure you run the script in your NEW database. (While we're on this subject, it's a good time to mention that you should back up your database before you start this process, and you should make changes to a test system before migrating it to production.)

That should move your stored procedures and user defined functions over.

You can use a similar process to move tables, views, users, and other objects over as well.

Jan 17, 2008 | Computers & Internet

1 Answer

Table not gettin updated

Generally database updates either require a commit to have the database perform the appropriate checking and actually flag the rows as part of the database. That Commit can occur in two ways -- some databases can be setup with an auto commit or auto rollback when the database is disconnected. The first means the programmer needs to do nothing. The second means if the programmer does not commit the updates are backed out of the database. To commit is generally considered bad because if there are any data errors partial transactions and logically inconsistent contents can exist in a database. For example entering an order for merchandise requires a single header row to identify the customer and multiple items rows to indicate what was ordered. If the third item record added to an order had an error and the application did not rollback and the database auto committed and incomplete order with only two items would be saved in the database. Traditionally databases with an automatic action at shutdown are set to rollback to assure such partial information is not saved. Even with auto rollback good programs detect errors and rollback themselves and allow users to continue.

The net result of the above is the probability that if the inserts actually occurred as you believe the there was a missing commit to confirm their addition to the database. and an automated rollback kept them from being completely added to the database. Another alternative is that the insert was not error checked in the program code and it failed meaning despite the program counter claiming rows were inserted in fact they were not.

Dec 07, 2007 | Computers & Internet

1 Answer

Help me....

You have to creat a table in the SQL server db then you can


a) use some windows host script or vb to read your data and insert into the db..


b)you can also use the acess:


Oct 13, 2007 | Microsoft SQL Server Standard Edition for...

Not finding what you are looking for?
Microsoft Visual Basic 6.0 for PC Logo

162 people viewed this question

Ask a Question

Usually answered in minutes!

Top Microsoft Computers & Internet Experts

micky dee

Level 3 Expert

2716 Answers

Piyal Perera
Piyal Perera

Level 3 Expert

528 Answers

Les Dickinson
Les Dickinson

Level 3 Expert

18390 Answers

Are you a Microsoft Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides