Database management insert,delete,update,search in microsoft access

 Today I have run a database management program using SQL,Oracal and microsoft access database system here i given the procedure how insert data in microsoft access if you follow my instruction then you will be successedshamim2.jpg

General Declaration:

Imports System

Imports System.Data

 Imports System.Data.OleDb

Write the following code on the click event:

Dim con As OleDbConnection

 Dim str As String

Dim sql As String

str = “Provider=Microsoft.Jet.oledb.4.0;Data Source=C:shamim.mdb;”

 con = New OleDbConnection

(str)sql = “insert into students(name,roll,email,mobile)values(‘” & TextBox1.Text & “‘,'” & TextBox2.Text & “‘,'” & TextBox3.Text & “‘,'” & TextBox4.Text & “‘)”

Dim cmd As OleDbCommand

Try

con.Open()cmd = New OleDbCommand

(Sql, con)cmd.ExecuteNonQuery()

TextBox1.Text = “”

TextBox2.Text = “”

TextBox3.Text = “”

TextBox4.Text = “”  MessageBox.Show(“Insert Successfully”)con.Close()Catch  ex As OleDbException

MsgBox(ex.Message, MsgBoxStyle.Critical, “Oledb Error”)

End Try

Now I will give you for update click: Dim con As OleDbConnectionDim str As String Dim sql As String

str = “Provider=Microsoft.Jet.oledb.4.0;

Data Source=C:shamim.mdb;”

con = New OleDbConnection

(str)sql = “delete from students where roll='” & TextBox2.Text & “‘”

Dim cmd As OleDbCommand

Trycon.Open()cmd = New OleDbCommand(sql, con)cmd.ExecuteNonQuery()

TextBox1.Text = “”

TextBox2.Text = “”

TextBox3.Text = “”

TextBox4.Text = “” MessageBox.Show(“Deleted successfully”) con.Close() Catch ex As OleDbExceptionMsgBox(ex.Message, MsgBoxStyle.Critical, “Oledb Error”)End TryFor Updating data by Roll:

Dim con As OleDbConnection

Dim str As String

Dim sql As String str = “Provider=Microsoft.Jet.oledb.4.0;Data Source=C:shamim.mdb;”

con = New OleDbConnection(

str)sql = “update students set name='” & TextBox1.Text & “‘,mobile='” & TextBox4.Text & “‘,email='” & TextBox3.Text & “‘ where roll='” & TextBox2.Text & “‘” Dim cmd As OleDbCommand

 Try

con.Open()cmd = New OleDbCommand

(sql, con)cmd.ExecuteNonQuery() TextBox1.Text = “” TextBox2.Text = “”TextBox3.Text = “” TextBox4.Text = “”

 MessageBox.Show(“Updated successfully”)con.Close()  Catch ex As OleDbException MsgBox(ex.Message, MsgBoxStyle.Critical, “Oledb Error”)End TryFor Searching by Roll: Dim con As OleDbConnection Dim sql As String Dim str As Stringstr = “Provider=Microsoft.Jet.oledb.4.0;Data Source=C:\shamim.mdb;”con = New OleDbConnection(Str)sql = “select * from students where roll='” & TextBox2.Text & “‘”

Dim cmd As OleDbCommand

Dim r As OleDbDataReader

Try con.Open()cmd = New OleDbCommand(sql, con)r = cmd.ExecuteReader() 

If r.Read

Then

TextBox1.Text = r(“name”)TextBox4.Text = r(“mobile”)TextBox3.Text = r( “email”) ElseTextBox1.Text = “” TextBox2.Text = “”

TextBox4.Text = “”

 TextBox3.Text = “”

MessageBox.Show(“No Information found”)

End If con.Close() Catch ex As OleDbException MsgBox(ex.Message, MsgBoxStyle.Critical, “Oledb Error”)

 Catch

 ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical, “General Error”) End Tryshawing all data from data table:

str as stringstr1 As String

Dim con As OleDbConnectionstr = “Provider=Microsoft.Jet.oledb.4.0;Data Source=C:\shamim.mdb;”

con = New OleDbConnection

(str) Dim da As OleDbDataAdapter Dim tb As DataTableTry con.Open()str1 = “select name,roll,mobile,email from students” con.Close()da = New OleDbDataAdapter

(str1, con)tb = New DataTable(“student”) da.Fill(tb) DataGridView1.DataSource = tbCatch ex As OleDbException

MsgBox(ex.Message, MsgBoxStyle.Critical, “Oledb Error”) 

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical, “General Error”)

End Try

Due to unsufficient time i just pasted it from my program if you get some mising please inform me.

Advertisements

Trying for writtng bangla in my blog

jatio-shongit.gif

HELLO WELCOME TO MY PERSONAL SITE.

 I am Shamim Ahmed student of 3rd year 5th semister in computer science and Engineering dept.from Rajshahi University of Engineering and Technology, yesterday i  attend a seminer where the chief speaker was  Mr Hasin Hyder vai who is  now manager of trippertlabs, He delivered his spech about our current job trends. I have inspired from his spech. my special thanks to Hasin vai for visiting our campus……………………………..

                shamim1.jpg

need for you………….

I have completed a project on children learning in visual basic where i faced various problem so i want to give some code which may need for you.

 Option Explicit //declaration;
Dim Voice As SpVoice
Private Sub Form_Load()
    Set Voice = New SpVoice
End Sub
Private Sub ExitBtn_Click()
    Unload Form1
End Sub
Private Sub SpeakItBtn_Click()
    On Error GoTo Speak_Error
     If SaveToWavCheckBox Then
        SaveToWav
    Else
    If Not TextField.Text = “” Then
            Voice.Speak TextField.Text, SVSFlagsAsync
        End If
    End If
    TextField.SetFocus
    Exit Sub
   
Speak_Error:
    MsgBox “Speak Error!”, vbOKOnly
End Sub

Private Sub SaveToWav()
    Dim cpFileStream As New SpFileStream
    cpFileStream.Format.Type = SAFT22kHz16BitMono
    ComDlg.CancelError = True
    On Error GoTo Cancel
    ComDlg.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist + cdlOFNNoReadOnlyReturn
    ComDlg.DialogTitle = “Save to a Wave File”
    ComDlg.Filter = “All Files (*.*)|*.*|Wave Files ” & “(*.wav)|*.wav”
    ComDlg.FilterIndex = 2
    ComDlg.ShowSave
    cpFileStream.Open ComDlg.FileName, SSFMCreateForWrite, False
    Set Voice.AudioOutputStream = cpFileStream
    Voice.Speak TextField.Text, SVSFDefault
    cpFileStream.Close
    Set cpFileStream = Nothing
    Set Voice.AudioOutputStream = Nothing
Cancel:
    Exit Sub
End Sub

only you need to design a form including a textfield,two button,and a checkbox,then it will be nice project.

Now I am trying to be a php developered,  I know php allready I can  connect  MySQL database, insert,delete ,search and update data from table,  now i will try to learn javacript…… if you have any suggetion please comment me.  

Learning MYSQL i faced various problem such as how to connect data base, i seems my given cood will need for MYSQL beginer,

All program should write in the php program:
db_connect :
$link = mysql_connect (“localhost”, “”, “”)
or die (“Could not connect”);
print (“Connected successfully”);
mysql_close ($link);

Create database in the Mysql:
$link = mysql_pconnect (“localhost”, “”, “”)
or die (“Could not connect”);
if (mysql_create_db (“database_name”)) {
print (“Database created successfully\n”);
} else {
printf (“Error creating database: %s\n”, mysql_error ());
}

Show data from table
mysql_connect (“localhost”, “”, “”);
$result = mysql_db_query (“database_name”,”select * from table_name”);
while ($row = mysql_fetch_array ($result)) {
echo $row[“user_id”];
echo $row[“fullname”];
}
mysql_free_result ($result);

Show table from database:
mysql_connect (“localhost”,””,””);
$result = mysql_list_tables (“database_name”);
$i = 0;
while ($i < mysql_num_rows ($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
echo $tb_names[$i];
$i++;

}

Data insert in the database Table:
$query=”INSERT INTO table_name” .”(name,roll, dept, mobile, dis) VALUES “.”(‘$a’, ‘$b’, ‘$c’, ‘$d’, ‘$e’)”;
mysql_query($query);

Delete data from table:
mysql_query(“DELETE FROM `table_name` WHERE roll = ‘$a’ “)]