Friday, June 4, 2010

Connecting to Database by writing code in VB.NET (Widout wizard)

Step 1. Add reference to system.data in your code

Click project->Add Reference

Select .Net tab

Select System.Data

Now click Ok.

Step 2. before Public Class Form1, write

Imports System.Data

Step 3. In Form load event

Dim Con As new OleDb.OleDbConnection

Step 4. Now write next

Con.Connectionstring=”PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydatabase.mdb”

End Sub

Step 5. Open the connection to database with

Con.Open()

and display a msgbox to test the successful connection

msgbox(“the connection is opened”)

Step 6. Create new dataset and data adapter.

Dim ds As New DataSet

Dim da As OleDb.OleDbDataAdapter

Step 7. Pass new sql query to the data adapter

Dim sql As String

sql=”SELECT * FROM mydatabasetable1”

da=New OleDb.OleDbDataAdapter(sql,con)

This is how your Code should look like

oledbCodeNew

Finally Fill the dataset with data.

da.Fill(ds,”mybase”)

This connects the database to dataset and fills it. Just that the data can’t be seen till now by anyone since it is not binded to any user viewable control.

txtFirstName.Text = ds.Tables("mydatabasetable").Rows(0).Item(1)

for further reading…http://www.homeandlearn.co.uk/NET/nets12p6.html

Final sample code::::::

 


Private Sub Frmmain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn As New OleDb.OleDbConnection
    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pdjm.accdb;Persist Security Info=True;Jet OLEDB:Database Password=password123"
    Dim ds As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim sql As String
    sql = "SELECT * FROM programmgmt"
    da = New OleDb.OleDbDataAdapter(sql, conn)
    da.Fill(ds, "mybase")
    DataGridView1.DataSource = ds.Tables("MyBase")

Wednesday, June 2, 2010

How to keep the background image static and let the whole fore-page scroll???

This is done using CSS and is very simple indeed!

here is the code

<center>
<body style=
"background-image: url('http://img.inkfrog.com/pix/KeepingBusy/BGinterlocksmall.gif'); background-repeat; background-position: 0px 50%; background-attachment: fixed">
<table border="0" width="650">
<tr>
<td width="100%" HEIGTH="600">
<table border="0" width="100%" cellspacing="0" cellpadding="0"
bgcolor="WHITE">
<tr>
<td width="100%">
<CENTER>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
X<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</center>

Printing a document in dot net.

printdialog1.document=printdocument1

printdialog1.printersettings=printdocument1.printersettings

printerdialog1.allowsomepages=true

if printdualog.showdialog=dialogresult.OK then

printdocumet1.printersettings=printdialog1.printersettings

printdocument1.print()

End if

 

For print preview button!

printpreviewdialog1.document=printdocument1

printpreviewdialog1.showdialog()

Passing variables amongst php pages and javascripts

http://www.skytopia.com/project/articles/compsci/form.html#jsvar2php

Tuesday, June 1, 2010

How to detect screen size using java script and assign to a usable variable?

var viewportwidth = 800, winh;
var viewportheight = 600, winw;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.screen.width != 'undefined')
{
      viewportwidth = window.innerWidth
      viewportheight = window.screen.height
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
{
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
}
// older versions of IE
else
{
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
winw = (65/100)*viewportwidth;

now this variable winw can be used as per needs!