Monday, May 10, 2010

How to Write a Class File in Asp.Net...

http://www.aspdotnetcodes.com/Creating_Class_File_Asp.Net.aspx

ScreenShot of Below CodePage..

TXTBOX...Enter Data Saving in the Mysql Table thru VB.Net Code

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click



Dim xx As String() = txtEmpdob.Text.Split("/")
Dim yy As String = (((xx(2).ToString & "-") + (xx(1).ToString & "-") + (xx(0).ToString)))
Dim cc As String() = txtEmpdoj.Text.Split("/")
Dim dd As String = (((cc(2).ToString & "-") + (cc(1).ToString & "-") + (cc(0).ToString)))


Dim strSql As String = ""
strSql = "insert into tab_employee (empcode,empname,empdob,empdoj,emplmntype,empdept,empnationality,empnricno,mthrtngue,mobileno,gender,maritalsts,religion,qualifications,certifications,specializations,yrsofexprnce,prvscomp,designation,lstdrawnsalary,noofmnthswrkd,awards,activities,hobbies,refname1,refcontact1,refname2,refcontact2,prsntaddress,permanentaddress) values('" & txtEmpCode.Text & "','" & txtEmpName.Text & "','" & yy & "','" & dd & "','" & ddlEmpType.SelectedValue & "','" & ddlEmpldept.SelectedValue & "','" & txtempnasnlty.Text & "','" & txtEmpnric.Text & "','" & txtEmpmthrtng.Text & "','" & txtEmpmobile.Text & "','" & ddlEmpGender.SelectedValue & "','" & ddlmaritalsts.SelectedValue & "','" & ddlreligion.SelectedValue & "','" & ddlqualifications.SelectedValue & "','" & txtEmpcertifi.Text & "','" & txtEmpSpeclzsn.Text & "','" & txtEmpyrsfexp.Text & "','" & txtEmpprvcomp.Text & "','" & txtEmpDesigntsn.Text & "','" & txtEmplstdrwnsal.Text & "','" & txtEmpmnthswrkd.Text & "','" & txtEmpAwards.Text & "','" & txtEmpActivities.Text & "','" & txtEmphobbies.Text & "','" & txtrefname1.Text & "','" & txtrefcontact1.Text & "','" & txtrefname2.Text & "','" & txtrefcontact2.Text & "','" & txtpresentadd.Text & "','" & txtpermanent.Text & "')"


sqlDB.savedata(strSql)
End Sub

Image Upload Example With Code in VB



Protected Sub btnupload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupload.Click


If Path.GetExtension(fileupld.PostedFile.FileName).ToString.ToLower = ".jpg" Then
Dim filename As String
filename = DateTime.Now.ToString("ddMMyyyyhhmmss") & Path.GetFileName(fileupld.PostedFile.FileName)
hdnfield.Value = filename
fileupld.PostedFile.SaveAs(Server.MapPath("photo") & "/" & filename)
WebMsgBox.Show("Photo Uploaded Successfully")
EmpImage1.ImageUrl = "~/Photo/" & filename
Else
WebMsgBox.Show(" incorrect File")
End If
End Sub

VB MysqlDb Connection "Class" File.....

Imports Microsoft.VisualBasic
Imports System.Data
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System
Imports System.Data.Odbc

Public Class mysqldb
Dim con As New MySqlConnection
Private str As String
Dim constate As Boolean = False

Private ds As New DataSet
Private da As New MySqlDataAdapter
Private dt As DataTable
Private strStatus As String
Private Cmd As New MySqlCommand
Public Sub New()

Try
con.ConnectionString = (ConfigurationManager.AppSettings("conobj"))
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If
Catch ex As System.Exception
Throw New System.Exception("Error Occured in Opening DataBase, Contact Administrator!")
constate = False
End Try
End Sub

Public Function gettable(ByVal str As String, ByVal dt As DataTable) As DataTable
Try
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If

da = New MySqlDataAdapter(str, con)
ds = New DataSet()
da.Fill(ds)
dt = ds.Tables(0)

Catch ex As System.Exception

End Try
con.Close()
Return dt
End Function

Public Sub filldll(ByVal str As String, ByVal ddl As DropDownList)

Try
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If
Dim ds1 As New DataSet
Dim da1 As New MySqlDataAdapter(str, con)
da1.Fill(ds1)
ddl.DataSource = ds1
ddl.DataTextField = "txt"
ddl.DataValueField = "val"
ddl.DataBind()
Catch ex As Exception
End Try
con.Close()
ddl.Items.Insert(0, "Select")
End Sub

Public Sub filllist(ByVal str As String, ByVal list As ListBox)

Try
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If

Dim ds1 As New DataSet
Dim da1 As New MySqlDataAdapter(str, con)
da1.Fill(ds1)
list.DataSource = ds1
list.DataTextField = "txt"
list.DataValueField = "val"
list.DataBind()
Catch ex As Exception
End Try
con.Close()
'list.Items.Insert(0, "---Select---")
End Sub

Public Sub savedata(ByVal str As String)
Try
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If
Dim cmd As New MySqlCommand(str, con)
cmd.ExecuteNonQuery()
Catch ex As Exception
End Try
con.Close()
End Sub

Public Function returnDataset(ByVal str As String) As DataSet

Try
''con.ConnectionString = (ConfigurationManager.AppSettings("conobj"))
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If
da = New MySqlDataAdapter(str, con)
ds = New DataSet()
da.Fill(ds)
Return ds
Catch ex As Exception
Return Nothing
Finally
ds.Dispose()
con.Close()
da.Dispose()
End Try
End Function

Public Function returnExecuteNonQuery(ByVal str As String) As String

Try
''con.ConnectionString = (ConfigurationManager.AppSettings("conobj"))
If con.State <> ConnectionState.Open Then
con.Open()
constate = True
End If
Cmd = New MySqlCommand(str, con)
strStatus = Cmd.ExecuteNonQuery()
Return strStatus
Catch ex As Exception
Return ex.Message.ToString()
Finally
con.Close()
Cmd.Dispose()
End Try
End Function
End Class

VB to C# & C# to VB Code Convert Tools..

http://www.dotnetspider.com/convert/