If DataGridView1.Rows(_xdtRow).Cells(0).Value.ToString.Contains("Team") = True Then
DataGridView1.Rows(_xdtRow).Cells(0).Value="Team that have replaced!"
Friday, September 19, 2014
vb.net ( replace data in datagridview )
vb.net (add data to datagridview with condition)
Dim _xdtRow As Integer = 0
For _xdtRow = 0 To odt2.Rows.Count - 1
If Dgvuserlist.Rows.Count < 0 Then
Dgvuserlist.Rows.Clear()
Else
If odt2.Rows(_xdtRow).Item(5).ToString = "0" Then
Dgvuserlist.Rows.Add("Male")
Else
Dgvuserlist.Rows.Add("Female")
End If
End If
Next
For _xdtRow = 0 To odt2.Rows.Count - 1
If Dgvuserlist.Rows.Count < 0 Then
Dgvuserlist.Rows.Clear()
Else
If odt2.Rows(_xdtRow).Item(5).ToString = "0" Then
Dgvuserlist.Rows.Add("Male")
Else
Dgvuserlist.Rows.Add("Female")
End If
End If
Next
vb.net (Add data to datatable)
Dim workRow As DataRow = odt2.NewRow()
workRow("Company ID") = 2
odt2.Rows.Add(workRow)
workRow("Company ID") = 2
odt2.Rows.Add(workRow)
Monday, September 15, 2014
vb.net (insert into table with store procedure)
Public Class Form1
Public conn As OdbcConnection
Public comm As OdbcCommand
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conn = New OdbcConnection("dsn=test;uid=root")
conn.Open()
'Add the call to the stored procedure including the connection
Dim cmd As New Odbc.OdbcCommand("{ CALL sp_insertuser2(?,?) }", conn)
cmd.CommandType = CommandType.StoredProcedure
'add the parameter to the stored procedure
Me.TextBox1.Text = CInt(10)
Me.TextBox2.Text = 2
Dim IDP As OdbcParameter = cmd.Parameters.Add("@ID", OdbcType.Int)
Dim NameP As OdbcParameter = cmd.Parameters.Add("@Name", OdbcType.Text)
IDP.Value = 3
NameP.Value = "ratana 3"
cmd.ExecuteNonQuery()
Conn.Close()
Conn.Dispose()
End Sub
End Class
Public conn As OdbcConnection
Public comm As OdbcCommand
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
conn = New OdbcConnection("dsn=test;uid=root")
conn.Open()
'Add the call to the stored procedure including the connection
Dim cmd As New Odbc.OdbcCommand("{ CALL sp_insertuser2(?,?) }", conn)
cmd.CommandType = CommandType.StoredProcedure
'add the parameter to the stored procedure
Me.TextBox1.Text = CInt(10)
Me.TextBox2.Text = 2
Dim IDP As OdbcParameter = cmd.Parameters.Add("@ID", OdbcType.Int)
Dim NameP As OdbcParameter = cmd.Parameters.Add("@Name", OdbcType.Text)
IDP.Value = 3
NameP.Value = "ratana 3"
cmd.ExecuteNonQuery()
Conn.Close()
Conn.Dispose()
End Sub
End Class
Friday, September 12, 2014
vb.net (find self path)
Dim aPath As String
Dim aName As String
aName = System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0).FullyQualifiedName
aPath = System.IO.Path.GetDirectoryName(aName)
Dim bm_source As New Bitmap(Bitmap.FromFile(aPath & "\advancedsettings.png"), 40, 40)
Dim aName As String
aName = System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0).FullyQualifiedName
aPath = System.IO.Path.GetDirectoryName(aName)
Dim bm_source As New Bitmap(Bitmap.FromFile(aPath & "\advancedsettings.png"), 40, 40)
Friday, August 29, 2014
vb.net (Assign linq to array)
Imports System
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Odbc
Imports System.Data.Common
Public Class UserList
Dim odt As New DataTable
Dim ods As New DataSet
Dim arr As Array
Public Sub UserList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Form1.connect()
Form1.conn.Open()
Dim comm3 As OdbcCommand
comm3 = New OdbcCommand("SELECT * FROM `tbl_user`", Form1.conn)
Dim myDA As OdbcDataAdapter = New OdbcDataAdapter(comm3)
odt.Columns.Add("User ID", GetType(Int32))
odt.Columns.Add("First Name", GetType(String))
odt.Columns.Add("Last Name", GetType(String))
myDA.Fill(ods, "tbl_user")
myDA.Dispose()
'odt = ods.Tables(0)
Dim users As DataTable = ods.Tables("tbl_user")
ods.Dispose()
'Dim query = From user In users.AsEnumerable()
Dim query = From user In users
Select user
For Each u In query
' MsgBox(u.Field(Of String)("first_name"))
odt.Rows.Add(u.Field(Of Integer)("user_id"), u.Field(Of String)("first_name"), u.Field(Of String)("last_name"))
Next
'''''''''''''
arr = query.ToArray
'odt = ods.Tables(0)
dgView.DataSource = odt
dgView.AllowUserToAddRows = False
dgView.SelectionMode = DataGridViewSelectionMode.Full RowSelect
dgView.Columns(0).HeaderText = "User ID"
dgView.Columns(1).HeaderText = "First Name"
Dim columnHeaderStyle As New DataGridViewCellStyle()
columnHeaderStyle.BackColor = Color.Beige
columnHeaderStyle.Font = New Font("Tahoma", 10, FontStyle.Bold)
dgView.ColumnHeadersDefaultCel lStyle = columnHeaderStyle
Me.dgView.DefaultCellStyle.Fon t = New Font("Tahoma", 10)
dgView.ReadOnly = True
Form1.conn.Close()
End Sub
Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles ButtonClose.Click
Me.Close()
End Sub
Private Sub TextBoxsearch_TextChanged(send er As Object, e As EventArgs) Handles TextBoxsearch.TextChanged
Form1.connect()
Form1.conn.Open()
Dim comm3 As OdbcCommand
comm3 = New OdbcCommand("SELECT * FROM `tbl_user` where username like ?", Form1.conn)
comm3.Parameters.AddWithValue( "username", "%" & TextBoxsearch.Text & "%")
Dim myDA As OdbcDataAdapter = New OdbcDataAdapter(comm3)
odt.Clear()
myDA.Fill(ods, "tbl_user")
myDA.Dispose()
odt = ods.Tables("tbl_user")
dgView.DataSource = odt
End Sub
Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
FormUser.Show()
Dim dt As New DataTable
dt.Columns.Add("User ID", GetType(Int32))
dt.Columns.Add("First Name", GetType(String))
dt.Columns.Add("Last Name", GetType(String))
For Each u In arr
dt.Rows.Add(CInt(u(0)), u(1).ToString, u(2).ToString)
Next
DataGridView1.DataSource = dt
End Sub
End Class
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Odbc
Imports System.Data.Common
Public Class UserList
Dim odt As New DataTable
Dim ods As New DataSet
Dim arr As Array
Public Sub UserList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Form1.connect()
Form1.conn.Open()
Dim comm3 As OdbcCommand
comm3 = New OdbcCommand("SELECT * FROM `tbl_user`", Form1.conn)
Dim myDA As OdbcDataAdapter = New OdbcDataAdapter(comm3)
odt.Columns.Add("User ID", GetType(Int32))
odt.Columns.Add("First Name", GetType(String))
odt.Columns.Add("Last Name", GetType(String))
myDA.Fill(ods, "tbl_user")
myDA.Dispose()
'odt = ods.Tables(0)
Dim users As DataTable = ods.Tables("tbl_user")
ods.Dispose()
'Dim query = From user In users.AsEnumerable()
Dim query = From user In users
Select user
For Each u In query
' MsgBox(u.Field(Of String)("first_name"))
odt.Rows.Add(u.Field(Of Integer)("user_id"), u.Field(Of String)("first_name"), u.Field(Of String)("last_name"))
Next
'''''''''''''
arr = query.ToArray
'odt = ods.Tables(0)
dgView.DataSource = odt
dgView.AllowUserToAddRows = False
dgView.SelectionMode = DataGridViewSelectionMode.Full
dgView.Columns(0).HeaderText = "User ID"
dgView.Columns(1).HeaderText = "First Name"
Dim columnHeaderStyle As New DataGridViewCellStyle()
columnHeaderStyle.BackColor = Color.Beige
columnHeaderStyle.Font = New Font("Tahoma", 10, FontStyle.Bold)
dgView.ColumnHeadersDefaultCel
Me.dgView.DefaultCellStyle.Fon
dgView.ReadOnly = True
Form1.conn.Close()
End Sub
Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles ButtonClose.Click
Me.Close()
End Sub
Private Sub TextBoxsearch_TextChanged(send
Form1.connect()
Form1.conn.Open()
Dim comm3 As OdbcCommand
comm3 = New OdbcCommand("SELECT * FROM `tbl_user` where username like ?", Form1.conn)
comm3.Parameters.AddWithValue(
Dim myDA As OdbcDataAdapter = New OdbcDataAdapter(comm3)
odt.Clear()
myDA.Fill(ods, "tbl_user")
myDA.Dispose()
odt = ods.Tables("tbl_user")
dgView.DataSource = odt
End Sub
Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
FormUser.Show()
Dim dt As New DataTable
dt.Columns.Add("User ID", GetType(Int32))
dt.Columns.Add("First Name", GetType(String))
dt.Columns.Add("Last Name", GetType(String))
For Each u In arr
dt.Rows.Add(CInt(u(0)), u(1).ToString, u(2).ToString)
Next
DataGridView1.DataSource = dt
End Sub
End Class
Tuesday, August 26, 2014
vb.net Culture of Invariant
Imports System.Globalization
Imports System.IO
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Persist the date and time data.
Dim sw As New StreamWriter(".\DateData.dat")
' Create a DateTime value.
Dim dtIn As DateTime = DateTime.Now
' Retrieve a CultureInfo object.
Dim invC As CultureInfo = CultureInfo.InvariantCulture
' Convert the date to a string and write it to a file.
sw.WriteLine(dtIn.ToString("r", invC))
sw.Close()
' Restore the date and time data.
Dim sr As New StreamReader(".\DateData.dat")
Dim input As String = String.Empty
Do While sr.Peek() >= 0
input = sr.ReadLine()
Console.WriteLine("Stored data: {0}", input)
Console.WriteLine()
' Parse the stored string.
Dim dtOut As DateTime = DateTime.Parse(input, invC, DateTimeStyles.RoundtripKind)
' Create a French (France) CultureInfo object.
Dim frFr As New CultureInfo("fr-FR")
' Displays the date formatted for the "fr-FR" culture.
Console.WriteLine("Date formatted for the {0} culture: {1}",
frFr.Name, dtOut.ToString("f", frFr))
' Creates a German (Germany) CultureInfo object.
Dim deDe As New CultureInfo("de-De")
' Displays the date formatted for the "de-DE" culture.
Console.WriteLine("Date formatted for {0} culture: {1}",
deDe.Name, dtOut.ToString("f", deDe))
Loop
sr.Close()
' The example displays the following output:
' Stored data: Tue, 15 May 2012 16:34:16 GMT
'
' Date formatted for the fr-FR culture: mardi 15 mai 2012 16:34
' Date formatted for de-DE culture: Dienstag, 15. Mai 2012 16:34
End Sub
End Class
Imports System.IO
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Persist the date and time data.
Dim sw As New StreamWriter(".\DateData.dat")
' Create a DateTime value.
Dim dtIn As DateTime = DateTime.Now
' Retrieve a CultureInfo object.
Dim invC As CultureInfo = CultureInfo.InvariantCulture
' Convert the date to a string and write it to a file.
sw.WriteLine(dtIn.ToString("r", invC))
sw.Close()
' Restore the date and time data.
Dim sr As New StreamReader(".\DateData.dat")
Dim input As String = String.Empty
Do While sr.Peek() >= 0
input = sr.ReadLine()
Console.WriteLine("Stored data: {0}", input)
Console.WriteLine()
' Parse the stored string.
Dim dtOut As DateTime = DateTime.Parse(input, invC, DateTimeStyles.RoundtripKind)
' Create a French (France) CultureInfo object.
Dim frFr As New CultureInfo("fr-FR")
' Displays the date formatted for the "fr-FR" culture.
Console.WriteLine("Date formatted for the {0} culture: {1}",
frFr.Name, dtOut.ToString("f", frFr))
' Creates a German (Germany) CultureInfo object.
Dim deDe As New CultureInfo("de-De")
' Displays the date formatted for the "de-DE" culture.
Console.WriteLine("Date formatted for {0} culture: {1}",
deDe.Name, dtOut.ToString("f", deDe))
Loop
sr.Close()
' The example displays the following output:
' Stored data: Tue, 15 May 2012 16:34:16 GMT
'
' Date formatted for the fr-FR culture: mardi 15 mai 2012 16:34
' Date formatted for de-DE culture: Dienstag, 15. Mai 2012 16:34
End Sub
End Class
Subscribe to:
Posts (Atom)