Saturday, October 15, 2011

create user for mysql database using vb.net 2010

Private Sub MySQLfunction()
Dim MySQLcon As String
Dim xconn As MySql.Data.MySqlClient.MySqlConnection

'txtuname.text
'txtpass.text
'cbopri.text

'code para sa save button ng createuser form
'i check kung pareho ang password sa retype password
'kung hindi pareho ibalik ang focus sa txtpass.text
'at mag exit sub

'kung pareho ilagay ang code sa baba

If txtpass.Text.Trim <> txtretype.Text.Trim Then
MsgBox("Error: Password did not Match!", vbCritical, "Warning!")
txtretype.Clear()
txtpass.Focus()
txtpass.Select()
Exit Sub
End If

Try
If Not xconn Is Nothing Then xconn.Close()

MySQLcon = String.Format("Server = {0};Database={3}; User ID={1}; Password={2};Port={4};", xServer, xUserID, xPassword, "mysql", xPort)
'or
'MySQLcon = String.Format("Server = {0};Database={3}; User ID={1}; Password={2};Port={4};", xServer, xUserID, xPassword, dbname, xPort)
xconn = New MySqlConnection(MySQLcon)
xconn.Open()

Mysqlcmd(MySQLcon, "DELETE FROM USER WHERE `User` LIKE '" & txtuname.Text & "' AND `Host` LIKE 'localhost'")

Mysqlcmd(MySQLcon, "CREATE USER '" & txtuname.Text & "'@'%' IDENTIFIED BY '***';")
Mysqlcmd(MySQLcon, "SET PASSWORD FOR '" & txtuname.Text & "'@'%' = PASSWORD('" & txtpass.Text & "')")

Mysqlcmd(MySQLcon, "CREATE USER '" & txtuname.Text & "'@'localhost' IDENTIFIED BY '***';")
Mysqlcmd(MySQLcon, "GRANT SELECT, EXECUTE, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, LOCK TABLES ON `" & xDatabase & "`.* TO '" & txtuname.Text & "'@'%' WITH GRANT OPTION")
Mysqlcmd(MySQLcon, "SET PASSWORD FOR '" & txtuname.Text & "'@'localhost' = PASSWORD('" & txtpass.Text & "')")

Mysqlcmd(MySQLcon, "DELETE FROM USER WHERE `User` LIKE '" & txtuname.Text & "' AND `Host` LIKE '%'")


'FOR ADMIN ONLY
Mysqlcmd(MySQLcon, "GRANT ALL PRIVILEGES ON * . * TO '" & txtuname.Text & "'@'%' IDENTIFIED BY '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;")
'END OF ADMIN ONLY


Catch err As Exception
'MsgBox(err.Message.ToString)
End Try
End Sub

VB.Net 2010 and MS Excel 2007 (Code to access Excel File using vb.Net2010)

'Add reference to Microsoft.Office.Interop.Excel

Dim ExcelApp As New Microsoft.Office.Interop.Excel
Dim WSheet As New Microsoft.Office.Interop.Excel

'if the code above does not work then declare Wsheet as
'Dim WSheet As Microsoft.Office.Interop.Excel


Dim ExcelProcess As New Process

Try
WSheet = ExcelApp.Sheets("Sheet1")

Catch ex As Exception

ExcelProcess.Start(Application.StartupPath & "\reports\excelFile.xlsx")
WSheet = ExcelApp.Sheets("Sheet1")
ExcelApp.Visible = True
End Try

WSheet.Select()

MsgBox(WSheet.Range("C6:C6").Value)


Try
ExcelApp.Quit()
Catch ex As Exception
End Try

VB.Net 2010 and Crystal Report for .Net Step by Step Tutorial



Add New Windows Form


Choose Crystal Report


Click Close when Crystal Report Gallery Appears

Then, goto- Project- Project Name Properties

Click on Compile-Advanced Compile Options


Change Target Framework to .Net Framework 4 - click OK
Go back to your form-scroll down to Reporting Toolbox- and choose - CrystalReportViewer

- then define the area for your crystal report viewer-
name the report viewer "crviewer" or any name relevant to your report.

goto to solution Explorer-right click App.config-click open


click the image below and zoom-in, then type the highlighted code exactly as seen





paste the code below on your module

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Module Module_Name_Here

Friend RptDataset As New DataSet
Friend RptTbl As String

'RptFile will contain the path and the name of the crystal report you design
'Example: Application.Startup & "\reports\rptfile.rpt
Friend RptFile As String


End Module

'end of module


'frmcrypt_report

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

Dim CryRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument

CryRpt.Load(RptFile)

'the code below is a must to refresh your dataset
RptDataset.Reset()

'use your preferred code to dynamically query your database. the code is for mysql using
'a function that i created to query my database

da = MySelectRows(Mycon, sqlstring, RptTbl)
da.Fill(RptDataset, RptTbl)

'if you are to connect to a server use the code below to login to your server
'it is a must to login to your server.

CryRpt.DataSourceConnections.Item(0).SetConnection("127.0.0.1", "dbname", True)
CryRpt.DataSourceConnections.Item(0).SetLogon("userid", "password")

'end of login to server code

CryRpt.SetDataSource(RptDataset.Tables(RptTbl))

crviewer.ReportSource = CryRpt
crviewer.Refresh()

End Sub



'Code from the form which will call your crystal report form

RptFile = Application.StartupPath & "\REPORT\rptfile.rpt"
RptTbl = "table_name"
frmcrypt_report.ShowDialog()

Sunday, October 2, 2011

Make a solar cell in your kitchen


from http://scitoys.com/scitoys/scitoys/echem/echem2.html


A solar cell is a device for converting energy from
the sun into electricity. The high-efficiency solar
cells you can buy at Radio Shack and other stores are
made from highly processed silicon, and require huge
factories, high temperatures, vacuum equipment, and
lots of money.


If we are willing to sacrifice efficiency for the ability
to make our own solar cells in the kitchen out of materials
from the neighborhood hardware store, we can demonstrate
a working solar cell in about an hour.


Our solar cell is made from cuprous oxide instead of
silicon. Cuprous oxide is one of the first materials known
to display the photoelectric effect, in which light
causes electricity to flow in a material.



Thinking about how to explain the photoelectric effect is
what led Albert Einstein to the Nobel prize for physics,
and to the theory of relativity.


Materials you will need



The solar cell is made from these materials:


  1. A sheet of copper flashing from the hardware store.
    This normally costs about $5.00 per square foot.
    We will need about half a square foot.

  2. Two alligator clip leads.

  3. A sensitive micro-ammeter that can read currents
    between 10 and 50 microamperes. Radio Shack sells
    small LCD multimeters that will do, but I used a
    small surplus meter with a needle.

  4. An electric stove. My kitchen stove is gas, so I bought
    a small one-burner electric hotplate for about $25. The
    little 700 watt burners probably won't work -- mine is
    1100 watts, so the burner gets red hot.


  5. A large clear plastic bottle off of which you can cut the top.
    I used a 2 liter spring water bottle. A large mouth glass
    jar will also work.

  6. Table salt. We will want a couple tablespoons of salt.

  7. Tap water.

  8. Sand paper or a wire brush on an electric drill.

  9. Sheet metal shears for cutting the copper sheet.



How to build the solar cell



My burner looks like this:




The first step is to cut a piece of the copper sheeting
that is about the size of the burner on the stove. Wash your
hands so they don't have any grease or oil on them. Then
wash the copper sheet with soap or cleanser to get any oil
or grease off of it.
Use the sandpaper or wire brush to thoroughly clean the copper
sheeting, so that any sulphide or other light corrosion is
removed.


Next, place the cleaned and dried copper sheet on the burner
and turn the burner to its highest setting.




As the copper starts to heat up, you will see beautiful oxidation
patterns begin to form. Oranges, purples, and reds will cover the
copper.




As the copper gets hotter, the colors are replaced with a black
coating of cupric oxide. This is not the oxide
we want, but it will flake off later, showing the reds, oranges,
pinks, and purples of the cuprous oxide layer underneath.




The last bits of color disappear as the burner starts to glow red.




When the burner is glowing red-hot, the sheet of copper will be
coated with a black cupric oxide coat. Let it cook for a half
an hour, so the black coating will be thick. This is important,
since a thick coating will flake off nicely, while a thin coat
will stay stuck to the copper.




After the half hour of cooking, turn off the burner.
Leave the hot copper on the burner to cool slowly.
If you cool it too quickly, the black oxide will stay
stuck to the copper.




As the copper cools, it shrinks.
The black cupric oxide also shrinks.
But they shrink at different rates, which makes
the black cupric oxide flake off.




The little black flakes pop off the copper with
enough force to make them fly a few inches. This
means a little more cleaning effort around the stove,
but it is fun to watch.




When the copper has cooled to room temperature (this takes about
20 minutes), most of the black oxide will be gone. A light scrubbing
with your hands under running water will remove most of the small
bits. Resist the temptation to remove all of the black spots by
hard scrubbing or by flexing the soft copper. This might damage
the delicate red cuprous oxide layer we need to make to solar cell work.


The rest of the assembly is very simple and quick.


Cut another sheet of copper about the same size as the first one.
Bend both pieces gently, so they will fit into the plastic bottle
or jar without touching one another. The cuprous oxide coating
that was facing up on the burner is usually the best side to face
outwards in the jar, because it has the smoothest, cleanest surface.


Attach the two alligator clip leads, one to the new copper plate,
and one to the cuprous oxide coated plate. Connect the lead from
the clean copper plate to the positive terminal of the meter.
Connect the lead from the cuprous oxide plate to the negative
terminal of the meter.


Now mix a couple tablespoons of salt into some hot tap water.
Stir the saltwater until all the salt is dissolved.
Then carefully pour the saltwater into the jar, being careful not
to get the clip leads wet. The saltwater should not completely
cover the plates -- you should leave about an inch of plate
above the water, so you can move the solar cell around without
getting the clip leads wet.




The photo above shows the solar cell in my shadow as I took
the picture. Notice that the meter is reading about 6 microamps
of current.


The solar cell is a battery, even in the dark, and will usually
show a few microamps of current.




The above photo shows the solar cell in the sunshine.
Notice that the meter has jumped up to about 33 microamps
of current. Sometimes it will go over 50 microamps, swinging
the needle all the way over to the right.


How does it do that?



Cuprous oxide is a type of material called a semiconductor.
A semiconductor is in between a conductor, where electricity can
flow freely, and an insulator, where electrons are bound tightly
to their atoms and do not flow freely.


In a semiconductor, there is a gap, called a bandgap between
the electrons that are bound tightly to the atom, and the electrons
that are farther from the atom, which can move freely and conduct
electricity.


Electrons cannot stay inside the bandgap. An electron cannot gain
just a little bit of energy and move away from the atom's nucleus
into the bandgap. An electron must gain enough energy to move
farther away from the nucleus, outside of the bandgap.


Similarly, an electron outside the bandgap cannot lose a little
bit of energy and fall just a little bit closer to the nucleus.
It must lose enough energy to fall past the bandgap into the
area where electrons are allowed.


When sunlight hits the electrons in the cuprous oxide, some of the
electrons gain enough energy from the sunlight to jump past the bandgap
and become free to conduct electricity.


The free electrons move into the saltwater, then into the clean copper plate,
into the wire, through the meter, and back to the cuprous oxide plate.


As the electrons move through the meter, they perform the work needed to
move the needle. When a shadow falls on the solar cell, fewer electrons
move through the meter, and the needle dips back down.


A note about power



The cell produces 50 microamps at 0.25 volts.


This is 0.0000125 watts (12.5 microwatts).


Don't expect to light light bulbs or charge batteries with
this device. It can be used as a light detector or light meter,
but it would take acres of them to power your house.


The 0.0000125 watts (12.5 microwatts) is for a 0.01 square meter cell,
or 1.25 milliwatts per square meter. To light a 100 watt light bulb, it
would take 80,000 square meters of cuprous oxide for the sunlit side, and
80,000 square meters of copper for the dark electrode. To run a 1,000 watt
stove, you would need 800,000 square meters of cuprous oxide, and another
800,000 square meters of plain copper, or 1,600,000 square meters all together.
If this were to form the roof of a home, each home would be 282 meters
long and 282 meters wide
, assuming all they needed electricity for was
one stove.


There are 17,222,256.7 square feet in 1,600,000 square meters.
If copper sheeting costs $5 per square foot, the copper alone would cost
$86,110,283.50 USD. Making it one tenth the thickness can bring this down
to $8,611,028.35. Since you are buying in bulk, you might get it for half that,
or about $4,300,000.00.


If you used silicon solar panels costing $4 per watt, you could run the same
stove for $4,000.00. But the panels would only be about 10 square meters.


Or, for about a dollar, you can build a solar stove out of aluminum foil and cardboard.
For about $20, you can build a very nice polished aluminum parabolic solar cooker.