Pgmer 50 Master Poster Featured Poster

Please mark the thread as solved if it solved...

Pgmer 50 Master Poster Featured Poster

ds.tables("employees").row(0).item("id") only one row ur checking? Cant u validate at the back end? by just sending ur employee id as parameter?

Pgmer 50 Master Poster Featured Poster

What is ur problem? or where is the probelm?

Pgmer 50 Master Poster Featured Poster

if windows application you need to install the framework on the user machine. Which ur application needs in run time...

Pgmer 50 Master Poster Featured Poster

U cant make exe from web app. DLL's or ASPX pages have to be moved to the Server and you need to set the virutal directory for the application in IIS.

Pgmer 50 Master Poster Featured Poster

you can do this in ur select statement from SQL while loading the data...

SELECT Active= convert(bit,0),* from ur table name
Pgmer 50 Master Poster Featured Poster

Try something like this..

Private Shared _Instance As Form2 = Nothing
Public Shared Function Instance() As Boolean
        If _Instance Is Nothing OrElse _Instance.IsDisposed = True Then
            _Instance = New Form2
            Return False
        End If
        _Instance.BringToFront()
        Return True
    End Function

In calling form write this

If Form2.Instance = False Then
            Form2.ShowDialog()
        End If
Pgmer 50 Master Poster Featured Poster

So you need to check if already an instance of form is opened or not.. u can use singleton pattern.

Pgmer 50 Master Poster Featured Poster

Application.StartupPath

Pgmer 50 Master Poster Featured Poster

what is field? what is values? can give the details?......

Pgmer 50 Master Poster Featured Poster

are you saving ur changes by updating the database trough code?

Pgmer 50 Master Poster Featured Poster

If ur not loading Millions of records into grid then you can write custom code to serach for perticular record in grid using loop.

Pgmer 50 Master Poster Featured Poster

use MASK text box and set the pattern of phone number you want. you can also set ur custom format if you want...

Pgmer 50 Master Poster Featured Poster

Dim str As String = StrConv(txtName.Text, VbStrConv.ProperCase)
txtName.Text = str

Use this while saving ur data as mentioned by Phasma... Whats the problem in it?

Pgmer 50 Master Poster Featured Poster
Dim str1 As String = "Your string"
        RichTextBox1.Text = str1
        RichTextBox1.SelectionStart = RichTextBox1.Find(str1)

        RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)

New Font(RichTextBox1.Font, FontStyle.Bold) is having many overloaded methods probalbly you can get something there

Pgmer 50 Master Poster Featured Poster

Use the form closing event

Pgmer 50 Master Poster Featured Poster
Try
            Dim iCell1 As Integer
            Dim icell2 As Integer
            Dim icellResult As Integer
            iCell1 = DataGridView1.CurrentRow.Cells(1).Value
            icell2 = DataGridView1.CurrentRow.Cells(2).Value
            icellResult = iCell1 * icell2
            DataGridView1.CurrentRow.Cells(3).Value = icellResult

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
Make sure the selectionMode is set to cellSelect. Once user leaves the cell 3 it will get the calculated values in it.
Pgmer 50 Master Poster Featured Poster

In the cell leave event of Quantity column multiply the column of item amount and Quantity and set the cell value of total Amount column. And it is nice if u give Save button to save the records..

Pgmer 50 Master Poster Featured Poster

Then plz mark thread as solved if it solved and if possible post ur code if u have any different approach other than two above.

Pgmer 50 Master Poster Featured Poster

Hi Mitja.
Thanks for above code. i got to learn something today :) My code also works but its not as simple as urs... :)
but what if user enters one extra digit? Will it handle the outof range exception?

Pgmer 50 Master Poster Featured Poster
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim numtoDisturbute As String
        numtoDisturbute = Trim(txtSource.Text)
        If numtoDisturbute.Length = 0 Then Exit Sub
        Dim arr As New List(Of String)

        For Each Cha As Char In numtoDisturbute
            arr.Add(Cha)
        Next

        For i As Integer = 0 To arr.Count - 1
            Dim text As String = arr.Item(i)
            Select Case i
                Case 0
                    TextBox1.Text = text
                Case 1
                    TextBox2.Text = text
                Case 2
                    TextBox3.Text = text
                Case 3
                    TextBox4.Text = text


            End Select

        Next

    End Sub
Pgmer 50 Master Poster Featured Poster

Cool :) Then plz dont forget to mark the thread as solved.

Pgmer 50 Master Poster Featured Poster

After 19 and vefore line 20 u need to initialize the connetion to SQL again

Pgmer 50 Master Poster Featured Poster

If cn.State = ConnectionState.Closed Then
again u need to initilize the connection like cn=new Sqlconnection and cn.connectionstring=connectionInfo

Pgmer 50 Master Poster Featured Poster

Then give as
For ii As Integer = 1 To 22

Pgmer 50 Master Poster Featured Poster

Cool... :) Then plz mark thread as solved.

Pgmer 50 Master Poster Featured Poster
If ((DataGridView1.Columns.Count = 0) Or (DataGridView1.Rows.Count = 0)) Then
            Exit Sub
        End If

        'Creating dataset to export
        Dim dset As New DataSet
        'add table to dataset
        dset.Tables.Add()
        'add column to that table
        For i As Integer = 0 To DataGridView1.ColumnCount - 1
            dset.Tables(0).Columns.Add(DataGridView1.Columns(i).HeaderText)
        Next
        'add rows to the table
        Dim dr1 As DataRow
        For i As Integer = 0 To DataGridView1.RowCount - 1
            dr1 = dset.Tables(0).NewRow
            For j As Integer = 0 To DataGridView1.Columns.Count - 1
                dr1(j) = DataGridView1.Rows(i).Cells(j).Value
            Next
            dset.Tables(0).Rows.Add(dr1)
        Next

        Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass
        Dim wBook As Microsoft.Office.Interop.Excel.Workbook
        Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet

        wBook = excel.Workbooks.Add()
        wSheet = wBook.ActiveSheet()

        Dim dt As System.Data.DataTable = dset.Tables(0)
        Dim dc As System.Data.DataColumn
        Dim dr As System.Data.DataRow
        Dim colIndex As Integer = 0
        Dim rowIndex As Integer = 0

        For Each dc In dt.Columns
            colIndex = colIndex + 1
            excel.Cells(1, colIndex) = dc.ColumnName
        Next

        For Each dr In dt.Rows
            rowIndex = rowIndex + 1
            colIndex = 0
            For Each dc In dt.Columns
                colIndex = colIndex + 1
                excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)

            Next
        Next

        wSheet.Columns.AutoFit()
        Dim strFileName As String = "C:\test.xls"
        Dim blnFileOpen As Boolean = False
        Try
            Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(strFileName)
            fileTemp.Close()
        Catch ex As Exception
            blnFileOpen = False
        End Try

        If System.IO.File.Exists(strFileName) Then
            System.IO.File.Delete(strFileName)
        End If

        wBook.SaveAs(strFileName)
        excel.Workbooks.Open(strFileName)
        excel.Visible = True
Pgmer 50 Master Poster Featured Poster

You need to take the statement before running cmd.ExecuteNonQuery() line in debug mode and paste the Insert statement in SQL so you will come to know where is the syntax error. and will be easy to fix.May be missing some Quotes or something.
I guess its missing ")" at the end.

& dgv3.Rows(i).Cells(7).Value & ")"

Pgmer 50 Master Poster Featured Poster

After this line

Dim cmd As New OleDbCommand

Add this line

cmd.Connection = cn
Pgmer 50 Master Poster Featured Poster

Pass the connection to command object.

Pgmer 50 Master Poster Featured Poster

Have you tried changing the buid action? Any luck on that?

Pgmer 50 Master Poster Featured Poster

Which database are u using? what is rdr? are u not getting any syntax error?
IIF should work. Else try to handle the situation in SQL query itself.using ISNULL function in ur select statement.

Pgmer 50 Master Poster Featured Poster

Try chaning the build action to Compile or something else.
I am not sure about this as i never worked with MS Access DB.

Pgmer 50 Master Poster Featured Poster

ur line If Not IsDBNull(rdr.GetUInt32(0)) Then

remove that with IIf(IsDBNull(rdr.GetUInt32(0))), 0, rdr.GetUInt32(0)))) Then

Pgmer 50 Master Poster Featured Poster

Try this IIf(IsDBNull(rdr.GetUInt32(0))), 0, rdr.GetUInt32(0))))

Pgmer 50 Master Poster Featured Poster

At which line the error is? And what is the error description ?

Pgmer 50 Master Poster Featured Poster

When you make any changes in db and build the application , do your debug folder is having updated DB?

Pgmer 50 Master Poster Featured Poster

you need to copy the database in client machine, by making copylocal=true property.
So whenver you publish it takes the new file to build and copy in user machine.

Pgmer 50 Master Poster Featured Poster

Yes i was wrong.. Sorry.
Thanks Adam. :)

Pgmer 50 Master Poster Featured Poster

Try this code..

Try

            Dim cn As OleDbConnection
            cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
            cn.Open()


            Dim cmd As New OleDbCommand
            cmd.CommandType = Data.CommandType.Text
            Dim Strcommandtext As String = "insert into bom(matname1,matnum1,matqty1) VALUES("
            Dim values As String = ""
            For i As Integer = 0 To DataGridView1.Rows.Count - 1
                values = Strcommandtext & DataGridView1.Rows(i).Cells(5).Value & "," & DataGridView1.Rows(i).Cells(4).Value & "," & DataGridView1.Rows(i).Cells(7).Value
                ' Here you check wheater the Insert statement is correct or not. If not then correct the above line accordingly.
                cmd.CommandText = values
                cmd.ExecuteNonQuery()
            Next i
            cmd = Nothing
           
            cn.Close()
            MsgBox("Your Record Inserted Successfully ")

        Catch myException As Exception

            MsgBox("No Record Inserted" + myException.ToString())

        Finally
            'MsgBox("Closing Connection")


        End Try

Just dont copy and paste and run. Try to understand the code. you only can debug ur application and see whats going on...

Pgmer 50 Master Poster Featured Poster

Select @@rowcount from table where stu_name like ='kevin'

Pgmer 50 Master Poster Featured Poster

The code what you have given will not insert records into DB so i gave you the code how to loop through the datagridview and get the values and insert into db.

Pgmer 50 Master Poster Featured Poster

I am providing the skin for insert into db, you need to change as u needed.

Dim conn As SqlConnection
        Dim strCnn As String = "your connection string;"
        conn = New SqlConnection(strCnn)
         conn.Open()

        Try


            If DataGridView1.Rows.Count > 0 Then

                Dim cmdInsert As New SqlCommand
                cmdInsert.Connection = conn
                Dim strCommandText As String
                Dim values As String = ""

                strCommandText = "INSERT INTO your insert statement here)VALUES("
                For i As Integer = 0 To DataGridView1.Rows.Count - 1
                

                    values = strCommandText & "Prepare your Values to pass from Grid i mean get the Cell values you want to insert into db "
                    cmdInsert.CommandText = values
                    cmdInsert.ExecuteNonQuery()

                    values = ""
                Next
                cmdInsert = Nothing
            End If



        Catch ex As Exception
         MsgBox(ex.ToString)
        Finally
            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If
        End Try
Pgmer 50 Master Poster Featured Poster

Im getting confused here... on submit you want to insert grid values from dgv3 or ur want to select something from database?

Pgmer 50 Master Poster Featured Poster

Is button3_Click is submit? If yes where is ur insert statement?

Pgmer 50 Master Poster Featured Poster

queryITNameReader.HasRows is true? and control is coming to Dim it2 As String = queryITNameReader.Item("equipmentNameID") point? if it has row it should fetch and assign to it2

Pgmer 50 Master Poster Featured Poster

When ur debugging the code are you getting anything into it2? And which database are u using? i dont think ur using SQL, i guess its Access database.. please check if the Query is correct and also u have data in database for that select statement

Pgmer 50 Master Poster Featured Poster
Try
            Dim cn As SqlConnection
            Dim strCnn As String = "Your data base connection string"
            cn = New SqlConnection(strCnn)
            cn.Open()
            Dim comm As New SqlCommand("SELECT ItEquipmentNo  FROM tblITEquipmentName WHERE equipmentName LIKE '" & it & "%'", cn)
            '' If ur using Sp then Commandtype= CommandType.StoredProcedure if it is Text then comm.CommandType=CommandType.Text
            comm.CommandType = CommandType.Text
            Dim ds As SqlDataReader
            ds = comm.ExecuteScalar
            If ds.HasRows Then
                While ds.Read
                    ''
                    ' do what u want here using the data
                    Dim x As String = ds.Item("columnname")
                End While
            End If

            ''Close your connections and commands.
            cn.Close()

        Catch ex As Exception
            ''Handle error if any
        End Try

See if this can help u

Pgmer 50 Master Poster Featured Poster
Private Function ExtractNumbers(ByVal expr As String) As String
        Return String.Join(Nothing, System.Text.RegularExpressions.Regex.Split(expr, "[^\d]"))
    End Function

write this function in ur form and call this it will return only number in string.

Pgmer 50 Master Poster Featured Poster

you can use Case statement in comboboxselectedindexchanged event