Jx_Man 987 Nearly a Senior Poster Featured Poster

If I want to leave the date field blank, would that be a "NULL", or is there another entry that should be used?

You can use SqlDateTime.Null.
Read this : http://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqldatetime.null%28v=vs.80%29.aspx

Dim DateVal As SqlDateTime
DateVal = SqlDateTime.Null
cmd.Parameters("@Date").Value = DateVal

Also, since this is entered into a textbox, is there a date conversion that is required to write this to the data table?

cmd.Parameters("@Date").Value = DateTime.Parse(txtDate.Text)

Jx_Man 987 Nearly a Senior Poster Featured Poster

Developer Tab -> Insert -> More Controls -> Microsoft Date and Time Picker (SP4) -> Then drawing it

Jx_Man 987 Nearly a Senior Poster Featured Poster

Example : This code trying to load data from mysql and show it in datagrid.
Just try it. Lookout for user and password.

  1. add reference : Project -> Reference -> Microsoft ActiveX Data Objects 6.0 Library
  2. add component (datagrid) : Project -> Component -> Microsoft Windows Common Controls 6.0 (SP6)

Add Datagrid and button to form then write this following code :

Public Conn As New ADODB.Connection
Public rs As New ADODB.Recordset

Public Sub Connect()
    Dim ConnString As String
    Dim db_name As String
    Dim db_server As String
    Dim db_port As String
    Dim db_user As String
    Dim db_pass As String
    ' error traping
    On Error GoTo Connection_Error
    ' fill the variable
    db_name = "Address" 'database name
    db_server = "localhost" '
    db_port = "3306"    'default port is 3306
    db_user = "root"    'default user name.
    db_pass = ""  ' depend on your password on mysql
    '/Create connection string
    ConnString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_user & ";PWD=" & db_pass & ";PORT=" & db_port & ";OPTION=3"
    '/Open Connection
    With Conn
        .ConnectionString = ConnString
        .Open
    End With

    On Error GoTo 0
    Exit Sub

Connection_Error:
        MsgBox "Err Desc : " & Err.Description & Chr(13) & "Err Source : " & Err.Source, vbInformation, "Error"
End Sub

Private Sub Command1_Click()
    rs.CursorLocation = adUseClient
    rs.Open "SELECT * FROM AddressData", Conn, adOpenDynamic, adLockBatchOptimistic
    Set DataGrid1.DataSource = rs
End Sub

Private Sub Form_Load()
' connect when form loaded
Connect

End Sub

e421380732cc095d6a5617cec9470669

which …

Neji commented: Great example +2
Jx_Man 987 Nearly a Senior Poster Featured Poster

the link you gave there , it has a code there.. is that used in linking the database to the frontend?

Yes, a code for linking vb6 with Mysql but just few lines.
This is an example of connection vb6 with mysql:

Dim Conn As New ADODB.Connection
Dim ConnString As String
Dim db_name As String
Dim db_server As String
Dim db_port As String
Dim db_user As String
Dim db_pass As String

' fill the variable
db_name = "Address"
db_server = "localhost" '
db_port = "3306"    'default port is 3306
db_user = "root"    'default user name.
db_pass = ""  ' depend on your password on mysql
'/Create connection string
ConnString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_user & ";PWD=" & db_pass & ";PORT=" & db_port & ";OPTION=3"
'/Open Connection
With Conn
    .ConnectionString = ConnString
    .Open
End With

but in our class , they linked it without any code , an excerpt from my notes says

Yes, you can connect to mysql without code but using code and variable make your program flexible and can run in any computers.

Jx_Man 987 Nearly a Senior Poster Featured Poster

in college , the backend sql is being implemented with oracle 9i , how much does it change things if i use mysql? sorry if the questions are vague ... i dont really know much about vb or sql.. lot to learn.

Not much change. The point is you already learn SQL Language and it's not different when you use oracle or MySql.
Most important is approching method to access database.

http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/436793/tutor-create-register-form-with-vb-6.0-and-mysql-

can you suggest a few good books too?

i'm Sorry, i learning vb from net

Jx_Man 987 Nearly a Senior Poster Featured Poster

I have a college project related to creating banking software where vb6 is being used as the frontend

You can learn about add,update and delete data from database.
Also Encrypt and decrypt data.

if the members could guide me to some good books/links that would be great! looking forward to a good time with vb. :)

Jx_Man 987 Nearly a Senior Poster Featured Poster

1.Read this
2. You can compare date function using DateTime.Compare(date1, date2)
Ex :

    Dim date1 As Date = #08/01/2009 12:00AM#
    Dim date2 As Date = #08/01/2009 12:00PM#
    Dim result As Integer = DateTime.Compare(date1, date2)
    Dim relationship As String 

    If result < 0 Then
       relationship = "is earlier than" 
    ElseIf result = 0 Then
       relationship = "is the same time as"          
    Else
       relationship = "is later than" 
    End If

    Console.WriteLine("{0} {1} {2}", date1, relationship, date2)
    ' The example displays the following output: 
    '    8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM

More info : MSDN and this article

3.It's depend on your region. By default, the date format for SQL server is in U.S. date format MM/DD/YY.
Read this

Jx_Man 987 Nearly a Senior Poster Featured Poster

Update CurrentStock after Save data.
Do save and update at the same time.
You can post your code here to give more information.

Jx_Man 987 Nearly a Senior Poster Featured Poster

I Want to Check How Much PC's Are Connected On My LAN,

http://www.daniweb.com/software-development/vbnet/threads/310040/how-to-view-computers-connected-to-a-local-network

also if I Call The Database From Server PC to Client PC Then What Should be The Connection String

What kind of database?
Access : http://www.connectionstrings.com/access-2007
sql server 2008 : http://www.connectionstrings.com/sql-server-2008
More info http://www.connectionstrings.com/

Jx_Man 987 Nearly a Senior Poster Featured Poster

This Following code is using listview to make background colour and delete multiple items.

Private Sub SetListview()
' Set listview
With ListView1
    .View = lvwReport
    .FullRowSelect = True
    .ColumnHeaders.Add , , "Id", 1100
    .ColumnHeaders.Add , , "First Name", 1400
    .ColumnHeaders.Add , , "Last Name", 1400
    .ColumnHeaders.Add , , "Email", 1700
End With

' Insert Data
With ListView1.ListItems
    .Add , , "1"
    .Item(1).SubItems(1) = "Andre"
    .Item(1).SubItems(2) = "White"
    .Item(1).SubItems(3) = "Andre@White.com"

    .Add , , "2"
    .Item(2).SubItems(1) = "Danny"
    .Item(2).SubItems(2) = "Burnett"
    .Item(2).SubItems(3) = "Danny@Burnett.com"

    .Add , , "3"
    .Item(3).SubItems(1) = "Edward"
    .Item(3).SubItems(2) = "Carter"
    .Item(3).SubItems(3) = "Edward@Carter.com"

    .Add , , "4"
    .Item(4).SubItems(1) = "Anne"
    .Item(4).SubItems(2) = "Witter"
    .Item(4).SubItems(3) = "Anne@Witter.com"

    .Add , , "5"
    .Item(5).SubItems(1) = "Vicky"
    .Item(5).SubItems(2) = "Myron"
    .Item(5).SubItems(3) = "Vicky@Myron.com"
End With
End Sub

Private Sub MakeItColorful(lstview As ListView)
If lstview.ListItems.Count > 0 Then

    picBG.Width = lstview.Width
    picBG.Height = lstview.ListItems(1).Height * (lstview.ListItems.Count)
    picBG.ScaleHeight = lstview.ListItems.Count
    picBG.ScaleWidth = 1
    picBG.DrawWidth = 1
    picBG.Cls
    For i = 1 To lstview.ListItems.Count
        If (lstview.ListItems(i) Mod 2) = 0 Then
            picBG.Line (0, i - 1)-(1, i), &H80FFFF, BF
        Else
            picBG.Line (0, i - 1)-(1, i), &HC0FFC0, BF
        End If
    Next i

    lstview.Picture = picBG.Image
Else
    picBG.Cls
    lstview.Picture = picBG.Image
End If
End Sub

Private Sub Command1_Click()
    With ListView1
        For i = .ListItems.Count To 1 Step -1
            If .ListItems(i).Selected Then
                .ListItems.Remove (.ListItems(i).Index)
            End If
        Next
    End With

End Sub

Private Sub Form_Load()
With ListView1
    .GridLines = True
    .View = lvwReport
End With

SetListview
MakeItColorful ListView1

End Sub

825db81dd0b779fc92e89e8d34ec3404

Jx_Man 987 Nearly a Senior Poster Featured Poster

'is there any code like this?
userform1.input_date.value = userform1.input_date.lastValue

Nope.. I don't think it exist

i have a form and i have 2 input box.
Is there any way to restore the last input in reopening the Form.

You can save it into text file and access it whenever you need

Jx_Man 987 Nearly a Senior Poster Featured Poster
Jx_Man 987 Nearly a Senior Poster Featured Poster

try :

TempDate = dr.Item("Appointmentdate").ToString
TxtAppointmentdate.Text = TempDate.ToString("yyyy-MM-dd")
Jx_Man 987 Nearly a Senior Poster Featured Poster

Is it possible to select multiple records (rows) in "DataGrid"

Because I can't find any properties to enable for multiple selection.

Yes.. Just press ctrl while you selecting items.

delete all selected items?

I not sure you can do this. Your code just remove bookmark not remove the items.
Datagrid currently using for displaying data from database.

I didn't use database in my application.

Why not use listview instead of datagrid?

Jx_Man 987 Nearly a Senior Poster Featured Poster

Try this :

Dim com1 As New OleDb.OleDbCommand
com1 = con1.CreateCommand
com1.CommandText = "insert into Department(DNo,DName,Manager,AddressL1,AddressL2,City,Telephone,E-mail)values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "' )"
Jx_Man 987 Nearly a Senior Poster Featured Poster

please how can i create a database and link it to my VB6 application. i designed a VB application to hold bio-data that will be updated from time to time but am finding it difficult to create the access back-end for it. please any urgent help will be most welcomed

This is less information about what makes you hard to code it?
How far you doing this? Post your code and we'll trying to help it.
You can use ADODB to linked vb6 with access.

Jx_Man 987 Nearly a Senior Poster Featured Poster

Try this :

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    w = Picture1.Point(X, Y)
    R = w And RGB(255, 0, 0)

    G = Int((w And RGB(0, 255, 0)) / 256)
    B = Int(Int((w And RGB(0, 0, 255)) / 256) / 256)
    labelR.Caption = R
    labelR.Caption.Text = G
    labelR.Caption.Text = B
End Sub
Naruse commented: Thank you :) +3
Jx_Man 987 Nearly a Senior Poster Featured Poster

Hi imBaCodes,

This thread already marked as solved without any reply.
You can share the solution here. It will help another members who has same problem like you.

Thank You

Jx_Man 987 Nearly a Senior Poster Featured Poster

where can i put table headers, this code will loop on selected record on the table

Just add one row when you create a table.
Set SIATable = SIADoc.Tables.Add(SIADoc.Bookmarks("\endofdoc").Range, rs.RecordCount + 1, 7)

Fill first row with Column name before you get a data thorugh the looping.

        '....

        ' heading
        SIATable.Cell(0, 1).Range.Text = "Column 1"
        SIATable.Cell(0, 2).Range.Text = "Column 2"
        SIATable.Cell(0, 3).Range.Text = "Column 3"
        SIATable.Cell(0, 4).Range.Text = "Column 4"
        SIATable.Cell(0, 5).Range.Text = "Column 5"
        SIATable.Cell(0, 6).Range.Text = "Column 6"
        SIATable.Cell(0, 7).Range.Text = "Column 7"

        ' Fill other rows with data from database
        For siar = 2 To rs.RecordCount + 1
            siac = 1 To 7
                SIATable.Cell(siar, siac).Range.Text = rs(siac - 1).Value
                SIATable.Rows(siar).Range.Font.Size = 9
                SIATable.Rows(siar).Range.Font.Bold = False
            Next
        .MoveNext
        Next

how can i add date and time on the filename: SIADoc.SaveAs ("C:\Users\2mhzbrain\Desktop\Main Inventory - '"& DATE + TIME &"'.docx") this is not working, but this is what i want to happen on the file names. thanks

You can't do it with date and time.
Date and Time will return illegal string for file name.
Date = 4/2/2013
TIme = 12:36:53 PM
Windows will reject this character: \/:*?"<>

Jade_me commented: Nice. +2
Jx_Man 987 Nearly a Senior Poster Featured Poster

Selectedrow need you to select full row.
In datagridview properties, change datagridview SelectionMode to FullRowSelect.

Jx_Man 987 Nearly a Senior Poster Featured Poster

Well.. it works fine to me and its not about the mouse. You need to understand the codes more.
i'm traping the mouse event on label. It will make the label to follow the locations of mouse.
Just press the label and drag it around the form.

Jx_Man 987 Nearly a Senior Poster Featured Poster

I want it to move like in the image I posted in first post. Not jumping from one location to another.

then you should try my suggested code

Jx_Man 987 Nearly a Senior Poster Featured Poster

You must select it using sql query

Jx_Man 987 Nearly a Senior Poster Featured Poster
Jx_Man 987 Nearly a Senior Poster Featured Poster

Try something like this :

    Function FileText(ByVal filename As String) As String
        Dim handle As Integer

           ' ensure that the file exists
        If Len(Dir$(filename)) = 0 Then
            Err.Raise 53  ' File not found
        End If

           ' open in binary mode
        handle = FreeFile
        Open filename$ For Binary As #handle
           ' read the string and close the file
        FileText = Space$(LOF(handle))
        Get #handle, , FileText
        Close #handle
    End Function

Private Sub Command1_Click()
    Text1.Text = FileText("D:\image.txt")
End Sub
Jx_Man 987 Nearly a Senior Poster Featured Poster

You're welcome.
Don't forget to mark this thread as solved

Jx_Man 987 Nearly a Senior Poster Featured Poster

yes sir.

Then use sql query to delete it and refresh it.

Jx_Man 987 Nearly a Senior Poster Featured Poster

this is connected to database?

Jx_Man 987 Nearly a Senior Poster Featured Poster
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    MsgBox(e.KeyChar & " key is pressed")
End Sub
Jx_Man 987 Nearly a Senior Poster Featured Poster

Add this foloowing function :

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
        MsgBox("Enter")
        Return True
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Jx_Man 987 Nearly a Senior Poster Featured Poster

Try :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        Control actcontrol;
        Point preloc;

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            actcontrol = sender as Control;
            preloc = e.Location;
            Cursor = Cursors.Default;
        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (actcontrol == null || actcontrol != sender)
                return;
            var location = actcontrol.Location;
            location.Offset(e.Location.X - preloc.X, e.Location.Y - preloc.Y);
            actcontrol.Location = location;
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            actcontrol = null;
            Cursor = Cursors.Default;
        }
    }
}
Jx_Man 987 Nearly a Senior Poster Featured Poster

Currently, I have 3 listboxs' data, but I don't know how to create 3 columns and show them with datagrid control.
Does anyone give me a guid line how to show listbox's data with datagrid?

You can fill recordset with listbox items then you can set datagrid source with current recordset.

see this example :

Private Sub Command1_Click()
Dim rsTest As New ADODB.Recordset

' create new column in recordset named listbox1, listbox2, listbox3
' every column has unique name

With rsTest.Fields
.Append "Listbox1", adBSTR
.Append "Listbox2", adBSTR
.Append "Listbox3", adBSTR
End With

rsTest.Open
For i = 0 To List1.ListCount

' add every listbox items into each column

    With rsTest
        .AddNew
        .Fields("Listbox1") = List1.List(i)
        .Fields("Listbox2") = List2.List(i)
        .Fields("Listbox3") = List3.List(i)
        .Update
    End With
Next i

Set DataGrid1.DataSource = rsTest
End Sub

Private Sub Form_Load()
With List1
    For i = 1 To 10
        .AddItem i
    Next i
End With

With List2
    For j = 11 To 20
        .AddItem j
    Next j
End With

With List3
    For k = 21 To 30
        .AddItem k
    Next k
End With

End Sub

1da39ad35d02cd7d27315d1fb6cad87f

TnTinMN commented: nice example +8
Jx_Man 987 Nearly a Senior Poster Featured Poster

this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox_KeyDown);

Jx_Man 987 Nearly a Senior Poster Featured Poster

A nut for a jar of tuna

That makes sense.
@reverend jim and scidzilla : Thanks for correcting
@Aura : this following codes is modified with other members suggestion :

Function RemoveNonLetterChar(theString)
    strAlphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    For i = 1 To Len(theString)
        strChar = Mid(theString, i, 1)
        If InStr(strAlphaNumeric, strChar) Then
            CleanedString = CleanedString & strChar
        End If
    Next
    RemoveNonLetterChar = CleanedString
End Function

Private Sub Command1_Click()
    Dim Temp, Palindrome As String

    Temp = LCase(RemoveNonLetterChar(Text1.Text)) 'lower case and remove non letters char
    Palindrome = StrReverse(Temp)

    If StrComp(Temp, Palindrome, vbTextCompare) = 0 Then
        MsgBox "Palindrome!"
    Else
        MsgBox "Not a Palindrome!"
    End If
End Sub
Jx_Man 987 Nearly a Senior Poster Featured Poster

If you were to check the phrase "Able was I ere I saw Elba" without normalizing it would not be flagged as a palindrome. After normalizing it would be "ablewasiereisawelba" which would be flagged as a palindrome.

Nope. It also recognized as palindrome. StrReverse will completed reverse the words included the space.

Jx_Man 987 Nearly a Senior Poster Featured Poster

Use StrReverse() function to reserve the word/phrase. Compare the real words/phrase with reserved words/phrase.
Check out the result if it same or not.

Private Sub Command1_Click()
    Dim Palindrome As String

    Palindrome = StrReverse(Text1.Text)

    If StrComp(Text1.Text, Palindrome, vbTextCompare) = 0 Then
        MsgBox "Palindrome!"
    Else
        MsgBox "Not a Palindrome!"
    End If
End Sub
Jx_Man 987 Nearly a Senior Poster Featured Poster

Try :

For Each Control In Me.Controls
    If TypeOf Control Is TextBox Then
        Control.Text = ""
    End If
Next Control
Jx_Man 987 Nearly a Senior Poster Featured Poster

Still not working :/

Sorry..my bad. Wrong in my sample code.

Change :

txtStudentId.DataField = "student_Id"
txtStudentFirstName.DataField = "student_firstName"
....

To :

txtStudentId.Text = rs!student_Id
txtStudentFirstName.Text = rs!student_firstName
....

Or :

txtStudentId.Text = rs.Fields("student_Id").Value
txtStudentFirstName.Text = rs.Fields("student_firstName").Value
....
Jx_Man 987 Nearly a Senior Poster Featured Poster

Change :

txtStudentId.DataField = "student_Id"
txtStudentFirstName.DataField = "student_firstName"
....

To :

txtStudentId.DataField = rs!student_Id
txtStudentFirstName.DataField = rs!student_firstName
....

Or :

txtStudentId.DataField = rs.Fields("student_Id").Value
txtStudentFirstName.DataField = rs.Fields("student_firstName").Value
....
Jx_Man 987 Nearly a Senior Poster Featured Poster

Confused here. I can't understand what you want exactly.
You can't edit data in datagrid or you can't show data to the textboxes?

Jx_Man 987 Nearly a Senior Poster Featured Poster

Well,,you're the one who know which the best.
I give an example of trasnferin data from flexgrid to listview & datagrid.
Modified it as u needed
trasnfer

Jx_Man 987 Nearly a Senior Poster Featured Poster

Yes. I understand.
I mean at the first post, you use "Set Grid.DataSource = rs"
but in the last post you remove it and use 'looping' to read data from database then write manually it to flexgrid.

The logic is data loaded from database and it accomodated in recordset.
Mshflexgrid can use recordset as datasource. So after you get data in recordset with sql statement just set datasourece with current recordset. it will make data automaticaly loaded into flexgrid and i don't get any problems (no more column added)

You can use listview if you want to write data manually with looping.

See an attachment.

Jx_Man 987 Nearly a Senior Poster Featured Poster

what kind of database you want to use?
And how far you doing this?

Jx_Man 987 Nearly a Senior Poster Featured Poster

What you mean about using datagrid or listview?
Transfered it from flexgrid to datagrid/listview or using datagrid/listview for all operation?

Jx_Man 987 Nearly a Senior Poster Featured Poster

MSHFlexgrid can use recordset as datasource. Why you write it manually?
Just used Grid.DataSource = rs then it will loaded automaticaly to your MSHFlexgrid.
I think andre was tell it before.
See this example :

Private Sub GetData()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

    Set cn = New ADODB.Connection

    cn.Provider = "microsoft.jet.oledb.4.0"
    cn.CursorLocation = adUseClient
    cn.Open App.Path & "\Authors.mdb"

    Set rs = New ADODB.Recordset
    rs.Open "Select au_id as Id,author as Name,yearborn as Birthday from Authors", cn

     Set grid2.DataSource = rs

End Sub

Private Sub Form_Load()
    GetData
End Sub
Jx_Man 987 Nearly a Senior Poster Featured Poster
Select code as Code,tprice as Price,quantity as Quantity from tblstock
Jx_Man 987 Nearly a Senior Poster Featured Poster

Our school wanted us to use that. Even us students, are wondering on why we are still using that.

Okay.. Post your code. How far you doing this. Make some effort here.
Any problem then ask here, "BUT DON'T ASK HOW TO CODE IT".

Jx_Man 987 Nearly a Senior Poster Featured Poster

I think Without a new row your no 1 problem will appear again.

Jx_Man 987 Nearly a Senior Poster Featured Poster

Try to using Alias in your SQL Statement. It's working for me in vb.net version, but never test it in vb6 with flex grid.
Change alias with your desire column name.

Jx_Man 987 Nearly a Senior Poster Featured Poster

Try :

Private Sub grid1_Click()
    With grid2
        a = grid2.Rows - 1
        b = grid1.RowSel

        For j = 1 To grid1.Cols - 1
            grid2.TextMatrix(a, j) = grid1.TextMatrix(b, j)
        Next j
        .AddItem ""
    End With
End Sub