Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Displaying the data in Visual Basic 6.0 Datagrid Controls

Using the self made module that you have incorporated in your Visual Basic  6.0 project, you can use this in displaying the data you have in your MS Access or SQL Server.

Objects needed:
Datagrid
Form

Add Datagrid control in your form. By default, Datagrid is not included in the list of toolbox at the right side of Visual Basic 6.0. So you need to add this by clicking Project in the Menu Bar, then Components, or just hit Ctrl+t in your keyboard. Select Microsoft Datagrid Controls 6.0 (OLEDB), remember to check the checkbox opposite the component. Click apply, then OK.

Suppose you have a table named Account in your database, with fields: Username, Password

Drag the Datagrid in the form. Double click in the form or form_load and write the following code:

Dim rs as recordset
Set rs = gsql(“Select * from Account”)
If rs.recordcount <> 0 then
Set datagrid1.datasource = rs
End if


Finished, you can now display the contents of your database in the datagrid. You can put this code anywhere you want, in the button or in the textbox. This code is not fix, you can always change the sql query depending on what you need.

If this code did not function well, kindly check your configuration of the database module.

MORE STORIES at: wallyibong.blogspot.com

How to use the database module for VB6 and Access 2003

How to use the database connection module in visual basic 6.0
Well, you have read on how to create a module for database connectivity in Visual basic in my previous blog. Now, we are going to use the module in your created log-in form.


Let’s code. Let us first perform the function of logging in:
Suppose we have created two accounts in your table LoginTable:

e.g.
username Password
Wally password
Casuga pwd

Back to your design, double click the Log-in button and write the following codes:

Dim rs as recordset ‘this is just to set where you will store your record

Set rs = gsql(“SELECT * FROM LoginTable WHERE username = ‘” & txtUsername & ”’ and password = ‘” & txtpassword & ”’”
‘this is the query for retrieving username and password in the ms access dbase
If rs.recordcount <> 0 then
Msgbox “Access Granted”
Else
Msgbox “Access Denied”
End if


So Easy right? Once you have configured the module rightly, you can manipulate your database in a very easy manner. If not. Please review again how to connect your database in visual basic.

Microsoft Access and Visual Basic 6.0 Connectivity using self made Module

Got problem in Database connection in visual basic 6.0? Well, if you do understand the basics of visual basic, and knowledge in SQL commands, you can manipulate your database in any ways possible. I have created an easy step by step tutorial for you.
1. Open your MS Access and name the database as you want to be (e.g. MyDbase.mdb). Create your tables (e.g. LoginTable) with fields (e.g. username and password) and save it in your folder (e.g. c:/Test/).


2. Next stuff? Open your visual basic and create a design in your form of log-in.

3. After you have created a design, Click on Project in the Menu bar, choose Preferences and check Microsoft ActiveX Data Objects 2.0 Library, This is to include the link library for the database connection that we will be performing later.

4. After that, we will be creating our module for database connection. What is the help of this module? It is for us to minimize the time of coding in our forms and just call the function stored in our module. How to create a module? Click on Project, then Add Module

5. Just copy the code below and in your new module as it is
'This is gSQL and gDML updated version 1.1 released
'includes new features like gTestEMpty,gGetInfo,gGetReCSeT,gAPPendInFo
'wallyibong.blogspot.com

Public dept As String
Public zq As Recordset
Public getval(25) As Variant
Public getstud, getstudno As String
Public studid As String
Global total

Public Function gSQL(ByVal strSQL As String) As Recordset
Dim cnn As Connection
Dim rs As Recordset
Dim cmd As Command
Dim strcnn, con As String
Set cnn = New Connection
Set cmd = New Command
Set rs = New Recordset
Dim a As String

'connection string for sql server 2005 database
‘strcnn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa; Password=Wally;Initial Catalog=clearanceSystem;Data Source=WALLYBOY"
'connection string for Microsoft Access 2003 database
strcnn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\myDbase.mdb;uid=admin;pwd=;"

cnn.Open strcnn
cmd.ActiveConnection = cnn
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Open cmd
Set gSQL = rs
Set rs = Nothing
Set cmd = Nothing
Set cnn = Nothing
End Function
Public Sub gDML(ByVal strSQL As String)
Dim cmd As Command
Dim cnn As Connection
Dim strcnn As String
Set cmd = New Command
Set cnn = New Connection

'connection string for sql server 2005 database
‘strcnn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa; Password=Wally;Initial Catalog=clearanceSystem;Data Source=WALLYBOY"
'connection string for Microsoft Access 2003 database
strcnn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\myDbase.mdb;uid=admin;pwd=;"

cnn.Open strcnn
cmd.ActiveConnection = cnn
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
cmd.Execute
Set cnn = Nothing
Set cmd = Nothing
End Sub

6. Seems tricky and mind boggling but just Save your module as dbase.bas

7. Just to explain the code briefly, the above function is for PUBLIC SUB GSQL is for searching/retrieving records only in our database, the PUBLIC SUB GDML function is for Deleting, Updating and Inserting records purposes.

8. If you are using SQL Server Database, the connection string is already given in the module as commented but you have to change the following:
strcnn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa; Password=Wally;Initial Catalog=clearanceSystem;Data Source=WALLYBOY"

ID = (The Id of your SQL Server), My default ID is sa
Password = (The password of your SQL Server)
Catalog = (name of the database you have created in SQL Server where the tables are stored
Source = (The name of your server)

9. While if you are using Microsoft Access, the connection string is also given, just commented because you cannot use two databases at a time.
'connection string for Microsoft Access 2003 database
strcnn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\myDbase.mdb;uid=admin;pwd=;"

Dbq= (where your database should be located)
Uid = admin (yeah, don’t change it, it is always admin)
Pwd =if you have password (in my case, I haven’t any)
10. Finished. You can connect now to your database? But how can we use the module?

PHP for novice

Continuing my PHP tutorial study.
Yeah, I have downloaded and configured properly Apache, Mysql and my PHP last week, so now I will study the very basic about PHP. The Basic PHP Syntax. I just want to acknowledge my source for this.
A PHP scripting block always starts with . A PHP scripting block can be placed anywhere in the document.
On servers with shorthand support enabled you can start a scripting block with .
For maximum compatibility, I recommend that you use the standard form (

?>
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.
Below, I have an example of a simple PHP script which sends the text "Hello World" to the browser:



echo "Hello World";
?>



Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
Note: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.
________________________________________
Comments in PHP
In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.



//This is a comment

/*
This is
a comment
block
*/
?>



I want to acknowledge w3schools for this knowledge, just want you to share to all of you. It helps.

INTRODUCTION TO WEB PROGRAMMING USING PHP


Yeah, I am studying now PHP because I want to teach my students how their website be more interactive, but before we start, I just want you to know about the basic information about it.

PHP is a powerful tool for making dynamic and interactive Web pages.PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. I ask my student what is the meaning of PHP in my class but they don’t know. So here is the meaning of it.

  • PHP stands for PHP: Hypertext Preprocessor

  • PHP is a server-side scripting language, like ASP

  • PHP scripts are executed on the server

  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)

  • PHP is an open source software

  • PHP is free to download and use

What is a PHP File?

  • PHP files can contain text, HTML tags and scripts

  • PHP files are returned to the browser as plain HTML

  • PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?

  • MySQL is a database server

  • MySQL is ideal for both small and large applications

  • MySQL supports standard SQL

  • MySQL compiles on a number of platforms

  • MySQL is free to download and use

PHP + MySQL

  • PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Why PHP?

  • PHP runs on different platforms (Windows, Linux, Unix, etc.)

  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)

  • PHP is FREE to download from the official PHP resource: www.php.net

  • PHP is easy to learn and runs efficiently on the server side

Where to Start?

To get access to a web server with PHP support, you can:

  • Install Apache (or IIS) on your own server, install PHP, and MySQL

  • Or find a web hosting plan with PHP and MySQL support

Thanks google for this information: but I have another way to easily configure all of these:

Or Download Xampp

It is a free and open source cross-platform web server package, consisting mainly of the Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages. So you do not need to configure it one by one. Just download it and its complete.

Here is the link on where to download:

http://xampp.en.softonic.com/

After you have downloaded the xampp, just install it, next next next…..

Then if have installed it, you can now see the configuration of your web server by typing this in your browser: http://localhost/xampp/

My blog now is just for installation. I will study tomorrow how to create my first program in PHP….. Im excited to learn new things. So happy… good day to all.