30.7.11

Rotate Image with VB.NET

Hi Everybody,
I would like to discuss one of the most FAQs regarding how we can rotate image which in Picturebox control with VB.NET 2010 Windows application ? If you have any questions, please feel free to contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) We are creating a new Windows Application Project (rotate_image)



2-) We are designing this windows form in a similar way to the picture below



3-) We are writing this code

Dim bmp As Bitmap

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rotate_btn.Click


'create a graphics
Dim grp As Graphics



'create picturebox graphics
grp = PictureBox1.CreateGraphics


'rotate graphic
grp.RotateTransform(angle_txt.Text)

'drawimage start 0,0
grp.DrawImage(bmp, 0, 0)

grp.Dispose()




End Sub


Private Sub openimage_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openimage_btn.Click
'create a openfile dialog
Dim open_file As New OpenFileDialog


'give its filter
open_file.Filter = "JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif|All files (*.*)|*.*"


'if ok click at opendialog
If open_file.ShowDialog() = DialogResult.OK Then

'set bmp image from file path
bmp = Image.FromFile(open_file.FileName)

'show image on picturebox
PictureBox1.Image = bmp
End If


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'set picturebox size mode
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub


4-) Lets run application and clicks open image and rotate buttons







Have a great day

Yener Turkeli
yenerturkeli@v-basic.net

25.7.11

SQLBulkCopy for performance with VB.NET

Hi Everybody,
I would like to discuss one of the most FAQs regarding how we can use SqlBulkCopy for datatransfer with VB.NET 2010 Windows application ? If you have any questions, please feel free to contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

SqlBulkCopy has a excellent performance advantage over them. The SqlBulkCopy class can use to just write data in order to SQL Server tables. System.Data.SqlClient.SqlBulkCopy

1-) We are creating a new Windows Application Project (SQLBulkCopy)



2-) We are designing this windows form in a similar way to the picture below



3-) We are writing this codes

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class Form1



Function fill_datatable() As DataTable

'create a datatable
Dim my_datatable As New DataTable

'create a connection string
Dim my_connection_string As String = "Server=153.19.29.202;User ID=admin;Password=69699696;Persist Security Info=False;Database=mysql_database;Connect Timeout=30"

'create mysqlconnection
Dim my_Connection As New MySqlConnection(my_connection_string)

' get data from mysql database table
Dim myCommand As New MySqlCommand("Select username,address,email From users", my_Connection)


' create a database mysqladapter
Dim myadapter As New MySqlDataAdapter

'assign mycommand
myadapter.SelectCommand = myCommand

'fill datatable via myadapter
myadapter.Fill(my_datatable)

Return my_datatable
End Function



Private Sub datatable_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datatable_btn.Click

'create connectionstring to sql server database
Dim my_connection_string As String = "Data Source=(local); Integrated Security=true; Initial Catalog=customers;"

'create connection
Dim my_Connection As New SqlConnection(my_connection_string)

'open connection
my_Connection.Open()

'create a sqlbulkcopy
Dim sql_bulkcopy As New SqlClient.SqlBulkCopy(my_connection_string)

'set destinationtable
sql_bulkcopy.DestinationTableName = "backup_Customers"

'set timeout
sql_bulkcopy.BulkCopyTimeout = 30


Try

'write all customers data to the table
sql_bulkcopy.WriteToServer(fill_datatable())


Catch ex As Exception

'show if any exception
MsgBox(ex.Message)

End Try

'Close
sql_bulkcopy.Close()

'give message
MsgBox("Data Transfered Successfully from Mysql Database Table to the MSQLServer database table", MsgBoxStyle.Information, "SQLBulkCopy")


End Sub

Private Sub datareader_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datareader_btn.Click
'create connectionstring to sql server database
Dim my_connection_string As String = "Data Source=(local); Integrated Security=true; Initial Catalog=customers;"

'create connection
Dim my_Connection As New SqlConnection(my_connection_string)

'open connection
my_Connection.Open()


'create a command and get all customers
Dim myCommand As New SqlCommand("Select * From customers", my_Connection)

' create a database reader
Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

'create a sqlbulkcopy
Dim sql_bulkcopy As New SqlClient.SqlBulkCopy(my_connection_string)

'set destinationtable
sql_bulkcopy.DestinationTableName = "backup_Customers"

Try

'write all customers data to table
sql_bulkcopy.WriteToServer(myReader)

Catch ex As Exception

'show if any exception
MsgBox(ex.Message)

End Try

'Close
sql_bulkcopy.Close()

' close the reader
myReader.Close()

' close the connection
my_Connection.Close()

'give message
MsgBox("Data Transfered Successfully from MSQLServer Database Table to the MSQLServer database table", MsgBoxStyle.Information, "SQLBulkCopy")



End Sub


End Class

4-) Lets run application



5-) Click button and see the result




Have a great day

Yener Turkeli
yenerturkeli@v-basic.net

11.7.11

MySQL Connection with VB.NET

Hi Everybody,
I would like to discuss one of the most FAQs regarding how we can connect MYSQL database table with VB.NET 2010 Windows application ? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-) Download Connector/Net (Connector/Net is a fully-managed ADO.NET driver for MySQL )

http://dev.mysql.com/downloads/connector/net/5.1.html




2-)Install application







3-)We are creating a new Windows Application Project (connect_mysql)



4-) Add Referrence




5-) We are designing this windows form in a similar way to the picture below




6-) We are writing this codes

Imports MySql.Data.MySqlClient


Public Class Form1

Private Sub get_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles get_btn.Click
'create a connection string
Dim my_connection_string As String = "Server=153.19.29.202;User ID=admin;Password=69699696;Persist Security Info=False;Database=mysql_database;Connect Timeout=30"

'create mysqlconnection
Dim my_Connection As New MySqlConnection(my_connection_string)

'create a datatable
Dim my_datatable As New DataTable


' get data from mysql database table
Dim myCommand As New MySqlCommand("Select username,address,email From users", my_Connection)


' create a database mysqladapter
Dim myadapter As New MySqlDataAdapter

'assign mycommand
myadapter.SelectCommand = myCommand

'fill datatable via myadapter
myadapter.Fill(my_datatable)

'show data in gridview
DataGridView1.DataSource = my_datatable
End Sub
End Class

7-)Lets run application and click get data button



Have a great day


Yener Turkeli
yenerturkeli@v-basic.net

2.7.11

Create Database Table with VB.NET


Hi Everybody,
I would like to discuss one of the most common FAQs regarding how we can create access database table with VB.NET 2010 Windows application code line? If any question, please feel free and contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

1-)We are creating a new Windows Application Project (database_table_create)



2-)We are designing this windows form in a similar way to the picture below



3-)We are writing this code

Imports System.Data
Imports System.Data.OleDb
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'connection string
Dim my_connection As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database\customers.mdb"

'query string
Dim my_query As String = "CREATE TABLE new_database ( Customer_Number Counter," & _
"Customer_Name TEXT(50) NOT NULL , Customer_Surname TEXT(40))"

'create a connection
Dim my_dbConnection As New OleDbConnection(my_connection)

'create a command
Dim my_Command As New OleDbCommand(my_query, my_dbConnection)

'connection open
my_dbConnection.Open()

'command execute
my_Command.ExecuteNonQuery()

'close connection
my_dbConnection.Close()



End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'connection string
Dim my_connection As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database\customers.mdb"

'insert (query string)
Dim my_query As String = "insert into new_database ( Customer_Name, Customer_Surname )" & _
" values ( 'jen' , 'Lte')"

'create a connection
Dim my_dbConnection As New OleDbConnection(my_connection)

'create a command
Dim my_Command As New OleDbCommand(my_query, my_dbConnection)

'connection open
my_dbConnection.Open()

'command execute
my_Command.ExecuteNonQuery()

'close connection
my_dbConnection.Close()
End Sub
End Class


4-)Lets run application and firstly click database table create button secondly insert sample data button.




5-) Lets check access database table


Have a great day
Yener Turkeli