dineshkumaar
Member
- Joined
- Jun 5, 2009
- Messages
- 21
- Programming Experience
- 10+
I am frustrated getting this message again and again.
I have developed a database with built in dataentry form. This database is distributed to many different users for dataentry. After data entry, I want to Merge all the user files to one Master Database. For that I wanted to create a merge utility in vb.net. The form will ask the Master Databse Location and 1 User database location. there are two datagridview for browising current table for Master and Databse and a start button to merge the table. When the start button is clicked, It will fill data from master and user database and start the merging. On clicking merege, I get the error - "Parameter ?_1 has no default value"
The entiore form code is given below
Please help me out!
Thanks
Dinesh Kumaar
I have developed a database with built in dataentry form. This database is distributed to many different users for dataentry. After data entry, I want to Merge all the user files to one Master Database. For that I wanted to create a merge utility in vb.net. The form will ask the Master Databse Location and 1 User database location. there are two datagridview for browising current table for Master and Databse and a start button to merge the table. When the start button is clicked, It will fill data from master and user database and start the merging. On clicking merege, I get the error - "Parameter ?_1 has no default value"
The entiore form code is given below
VB.NET:
Imports System.IO.Stream
Imports System.Data.OleDb
Imports System.Data
Imports System.Data.Common
Public Class Form1
Dim MasterFileName As String
Dim UserFileName As String
Dim strProviderM As String
Dim strSqlM As String
Dim ConM As OleDbConnection
Dim cmdM As OleDbCommand
Dim daM As OleDbDataAdapter
Dim faM As DataTable
Dim strProviderU As String
Dim ConU As OleDbConnection
Dim cmdU As OleDbCommand
Dim daU As OleDbDataAdapter
Dim faU As DataTable
'Dim tblNo As Int16
Dim TableNo As Int16
Dim TablesList() As String = {"FarmersAddress", "FarmersTelephone", "FarmersLands", "FarmersCrops", "FarmersBorewells", _
"FarmersIrrigation", "FarmersBorewells", "FarmersSugarCaneDisposal", _
"FarmersBiomass", "FarmersBankAcs"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnMaster_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMaster.Click
If Not ofdBrowse.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
Exit Sub
End If
MasterFileName = ofdBrowse.SafeFileName
txtMaster.Text = MasterFileName
End Sub
Private Sub btnChild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChild.Click
If Not ofdBrowse.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
Exit Sub
End If
UserFileName = ofdBrowse.SafeFileName
txtUser.Text = UserFileName
'Dim strProviderU As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + UserFileName + ";"
'Dim strSqlU As String = "SELECT * FROM FarmersAddress"
'Dim conU As New OleDbConnection(strProviderU)
'Dim cmdU As New OleDbCommand(strSqlU, conU)
'conU.Open()
'cmdU.CommandType = CommandType.Text
'Dim daU As New OleDbDataAdapter(cmdU)
'Dim faU As New DataTable("FarmersAddress")
'daU.Fill(faU)
'dgvUser.DataSource = faU
End Sub
Private Sub MergeTables()
Dim UserRow As DataRow
Dim MasterRow As DataRow
Dim n As Int16 = 0
Dim Errors As Int16 = 0
Dim ProgStep As Int16 = faU.Rows.Count / 100
Dim SelectCmdText As String
Dim InsertCmdText As String
Dim UpdateCmdText As String
'Dim CmdParText As String
Dim ColName As String
Dim dbColumn As DataColumn
For Each UserRow In faU.Rows
SelectCmdText = "Select "
InsertCmdText = "Insert into `" + TablesList(TableNo) + "` ("
UpdateCmdText = "Update `" & TablesList(TableNo) & "` Set "
MasterRow = faM.NewRow()
daM.InsertCommand = New OleDbCommand
daM.InsertCommand.Connection = ConM
For n = 0 To faU.Columns.Count - 1
ColName = faU.Columns(n).ColumnName
SelectCmdText += "[" + ColName + "]" + ", "
ColName = "[" + ColName + "]"
dbColumn = faU.Columns(n)
InsertCmdText += ColName + ", "
daM.InsertCommand.Parameters.Add(ColName, GetOleDbType(dbColumn.DataType))
'daM.InsertCommand.Parameters(ColName).Value = DBNull.Value
'daM.InsertCommand.CommandText = "insert into FarmersAddress(FarmersName) values (?)"
'daU.UpdateCommand.Parameters.Add(ColName, GetOleDbType(dbColumn.DataType))
MasterRow(n) = UserRow(n)
'If Len(MasterRow(n).ToString.Trim) = 0 Then
' MasterRow(n) = #1/1/2009#
'End If
txtMsg.Text += vbCrLf + UserRow(n).ToString
Next
InsertCmdText = Mid(InsertCmdText, 1, Len(InsertCmdText) - 2) + ")" + " Values("
SelectCmdText = Mid(SelectCmdText, 1, Len(SelectCmdText) - 2) + " From " + TablesList(TableNo)
For n = 0 To faU.Columns.Count - 1
InsertCmdText += "?, "
Next
InsertCmdText = Mid(InsertCmdText, 1, Len(InsertCmdText) - 2) + ")"
txtMsg.Text += InsertCmdText + vbCrLf
'"INSERT INTO `FarmersAddress` (`UnitCode`, `CaneGrowerNo`, `FarmerName`, `FathersName`, `Village`, `Panchayat`, `StateCode`, `DistrictCode`, `Pincode`, `Block Code`, `DOB`, `BPLstatus`, `DifferentMailAddress`, `MVillage`, `MPanchayat`, `MStateCode`, `MDistrictCode`, `MPincode`, `Age`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
'"INSERT INTO FarmersAddress (UnitCode, CaneGrowerNo, FarmerName, FathersName, Village, Panchayat, StateCode, DistrictCode, Pincode, Block Code, DOB, BPLstatus, DifferentMailAddress, MVillage, MPanchayat, MStateCode, MDistrictCode, MPincode, Age) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
'InsertCmdText = "INSERT INTO `FarmersAddress` (`UnitCode`, `CaneGrowerNo`, `FarmerName`, `FathersName`, `Village`, `Panchayat`, `StateCode`, `DistrictCode`, `Pincode`, `Block Code`, `DOB`, `BPLstatus`, `DifferentMailAddress`, `MVillage`, `MPanchayat`, `MStateCode`, `MDistrictCode`, `MPincode`, `Age`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
daM.SelectCommand.CommandText = SelectCmdText
daM.InsertCommand.CommandText = InsertCmdText
Try
daM.Fill(faM)
Catch
End Try
faM.Rows.Add(MasterRow)
Try
'faM.AcceptChanges()
'faM.BeginInit()
'faM.EndInit()
daM.Update(faM)
MsgBox("success")
Catch ex As Exception
txtMsg.Text += vbCrLf + ex.Message + vbCrLf + "Stack Trace : -->" + ex.StackTrace + vbCrLf + "Source: -->" + vbCrLf + ex.Source + vbCrLf
Errors += 1
End Try
ProgressBar.Value += ProgStep
Next
txtMsg.Text += vbCrLf + "Merge Completed with " + Errors.ToString + " Errors"
txtMsg.Text += vbCrLf + "-------------------------------------------------------------------------------"
txtMsg.Text += vbCrLf + vbCrLf
End Sub
Private Sub ShowTables()
For tblNo = 0 To TablesList.Length - 1
ConM = New OleDbConnection
cmdM = New OleDbCommand
daM = New OleDbDataAdapter
ConU = New OleDbConnection
cmdU = New OleDbCommand
daU = New OleDbDataAdapter
strProviderM = New String("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + MasterFileName + ";")
ConM.ConnectionString = strProviderM
strProviderU = New String("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + UserFileName + ";")
ConU.ConnectionString = strProviderU
strSqlM = "SELECT * FROM " & TablesList(tblNo)
'******************** Open Master Database
cmdM.CommandText = (strSqlM)
cmdM.Connection = ConM
ConM.Open()
cmdM.CommandType = CommandType.Text
daM.SelectCommand = cmdM
faM = New DataTable(TablesList(tblNo))
daM.Fill(faM)
dgvMaster.DataSource = faM
'******************** Open User Database
cmdU.CommandText = (strSqlM)
cmdU.Connection = ConU
ConU.Open()
cmdU.CommandType = CommandType.Text
daU.SelectCommand = cmdU
faU = New DataTable(TablesList(tblNo))
daU.Fill(faU)
dgvUser.DataSource = faU
txtMsg.Text += "Starting Merge Process for table: " + TablesList(tblNo) + Chr(13)
MergeTables()
Next
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
ShowTables()
End Sub
' Return the OleDbType that represents the specified system type
' This is particularly useful when you have a DataTable and want to create a
' OleDbParameter for onw of its columns, but don't know its type.
' DataColumnName.DataType returns a Type, and you can convert it to OleDbType
' by passing it to this function.
' Note: requires System.Data.OleDb
' Example:
' Dim param As New OleDbParameter("TestCol", GetOleDbType(String))
Private Function GetOleDbType(ByVal sysType As Type) As OleDbType
If sysType Is GetType(String) Then
Return OleDbType.VarChar
ElseIf sysType Is GetType(Integer) Then
Return OleDbType.Integer
ElseIf sysType Is GetType(Boolean) Then
Return OleDbType.Boolean
ElseIf sysType Is GetType(Date) Then
Return OleDbType.Date
ElseIf sysType Is GetType(Char) Then
Return OleDbType.Char
ElseIf sysType Is GetType(Decimal) Then
Return OleDbType.Decimal
ElseIf sysType Is GetType(Double) Then
Return OleDbType.Double
ElseIf sysType Is GetType(Single) Then
Return OleDbType.Single
ElseIf sysType Is GetType(Byte()) Then
Return OleDbType.Binary
ElseIf sysType Is GetType(Guid) Then
Return OleDbType.Guid
End If
End Function
End Class
Please help me out!
Thanks
Dinesh Kumaar
Last edited by a moderator: