Pgmer 50 Master Poster Featured Poster

Data grid shows the records in Columns only....
Whats ur problem? Explain plz

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

in ExcelWorkSheetObject.SaveAs(ExcelSheetName) method perorm the step.
After saving all the data make ProgressBar1.Maximum = 100.

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

Write the procedure at back end and pass the parameters from front end. Its always easy to manage the code.

Pgmer 50 Master Poster Featured Poster

Then give as
For ii As Integer = 1 To 22

Pgmer 50 Master Poster Featured Poster

What is the error? or what is the problem? plz explain

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
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 * from  Employee_Master", cn)
            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
                    TextBox2_name.Text = ds.Item(2)
                End While
            End If

            cn.Close()

        Catch ex As Exception
            MessageBox.Show(ex.ToString())

        Finally

        End Try
Pgmer 50 Master Poster Featured Poster
For i As Integer = 0 To DataGridView1.Rows.Count - 1
                TextBox1.Text = DataGridView1.Rows.Item("Pass index or Columnname").ToString
            Next
Pgmer 50 Master Poster Featured Poster

You need to get the row from grid and loop through the cells And assign to textboxes.

Pgmer 50 Master Poster Featured Poster

write the Stored procedure in ur DB for selecting the records from DB and get those details in dataset, loop through dataset and assign to textbox accordingly.

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

What is your code for this? Please post ur code and the problem with the code.

Pgmer 50 Master Poster Featured Poster

You need to prepare the insert statement and connections to ur DB. And run the query using command object. There are multiple similar threads u can refer to or google will help u.

Pgmer 50 Master Poster Featured Poster

This is called cascaded combobox. In cmb1 Selected index changed event you need to filter the records of dataset which urusing to bind the cmb2 using dataview and then bind the filtered resultset to cmb2.

Pgmer 50 Master Poster Featured Poster

You need to use either datareader or dataadapter methods to get the data from DB and then assign to textboxes by looping through ur dataset or datareader.

Pgmer 50 Master Poster Featured Poster

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

Pgmer 50 Master Poster Featured Poster

Combobox1.text

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

Will your Query will return just one row? And you want assign those result set to controls on form right?

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

I have given the complete code to get ur data from server. You just need to prepare connection string for SQL serever and Select statement. Where ur not able to understand my code?. We cannot write code for you here.

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

strCnn is the string variable you need to pass ur database connections string.
Like

Persist Security Info=true; Data Source="Server Name";UID = "User Id";PWD="Password for DB";Initial Catalog="Default database to connect";

And then get ur data into dataset by using fill command of dataadapter. And then assign the values to text box.

Pgmer 50 Master Poster Featured Poster
Dim fBrowse As New OpenFileDialog

            With fBrowse
                .Filter = "Excel files(*.xls)|*.xls|All files (*.*)|*.*"
                .FilterIndex = 1
                .Title = "Import data from Excel file"
            End With
            If fBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim fname As String
                fname = fBrowse.FileName
'' Do what you want to here.
End If

I have shown the file format for .xls and All files, U can give according to ur need.

Pgmer 50 Master Poster Featured Poster

you need to get the location of Lable and show the popup? or you in mouseclick event of LinkLable show the popup message.

Pgmer 50 Master Poster Featured Poster

How your loading the combobox in form 1? are u using dataset?

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("Your sp or Command text to get the data from DB", cn)
            '' If ur using Sp then Commandtype= CommandType.StoredProcedure if it   is  Text then comm.CommandType=CommandType.Text
            comm.CommandType = CommandType.StoredProcedure
            Dim da As New SqlDataAdapter(comm)
            Dim ds As New DataSet
            da.Fill(ds)
            'Ur dataset will have records
            ''Close your connections and commands.
        Catch ex As Exception
            ''Handle error if any
        End Try
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

Did your Childform set its parent form?

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

After inserting the records did you try running ur statement on database like
Select * from tblClass?

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

What you want to achieve? When you click on each link lable you will get the POPup? please explain.

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

Where ur executing the Query? where command object? how will you send back new value to db?