Hi Friends,
I am new to .Net. So I don't know much.
I am facing a problem in updating database through ADO.Net
I am creating the dataset and there is no problem in the updation and
deletion or insertion in the dataset but when I am updating the
database through adaptor error occures (Coloured Red).
For ref the code follows:
Code:
Imports System.Data.Ole Db
Module Module1
Private Const s As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=D:\Rabi\ Database\DBTest-1.mdb;Persist Security Info=False"
Public Con As OleDb.OleDbConn ection
Public adopt As OleDb.OleDbData Adapter
Public ds As DataSet
Public sql As String
Dim cmdDel As New OleDb.OleDbComm and, sDelSql As String
Dim cmdIns As New OleDb.OleDbComm and, sInsSql As String
Dim cmdUpd As New OleDb.OleDbComm and, sUpdSql As String
Dim Param As New OleDb.OleDbPara meter
Public Sub Display(ByRef Table As DataTable)
Dim row As DataRow
Dim col As DataColumn
Dim i, j As Integer
For i = 0 To Table.Rows.Coun t - 1
row = Table.Rows(i)
Select Case row.RowState
Case DataRowState.De leted
Console.WriteLi ne("[Deleted]")
Case DataRowState.Mo dified
Console.WriteLi ne("[Modified]")
Case DataRowState.Ad ded
Console.WriteLi ne("[Added]")
Case DataRowState.Un changed
Console.WriteLi ne("[Unchanged]")
End Select
For j = 0 To Table.Columns.C ount - 1
If row.RowState <> DataRowState.De leted Then
Console.WriteLi ne("{0}", row.Item(j))
End If
Next
Console.WriteLi ne()
Next
End Sub
Public Sub Main()
Try
Con = New OleDb.OleDbConn ection(s)
sql = "Select * from Artist"
adopt = New OleDbDataAdapte r(sql, Con)
ds = New DataSet
Catch ex As Exception
Console.WriteLi ne(ex.ToString)
Console.ReadLin e()
End Try
sDelSql = "Delete From Artist Where Id = ?"
cmdDel.Connecti on = Con
cmdDel.CommandT ext = sDelSql
Param = cmdDel.Paramete rs.Add("Id", OleDb.OleDbType .Integer)
Param.SourceCol umn = "@ID"
Param.SourceVer sion = DataRowVersion. Original
adopt.DeleteCom mand = cmdDel
sUpdSql = "Update Artist Set Name = ? Where Id = ?"
cmdUpd.Connecti on = Con
cmdUpd.CommandT ext = sUpdSql
Param = cmdUpd.Paramete rs.Add("Name", OleDb.OleDbType .Char)
Param.SourceCol umn = "@Name"
Param.SourceVer sion = DataRowVersion. Current
Param = cmdUpd.Paramete rs.Add("Id", OleDb.OleDbType .Integer)
Param.SourceCol umn = "@Id"
Param.SourceVer sion = DataRowVersion. Original
adopt.UpdateCom mand = cmdUpd
sInsSql = "Insert Into Artist (Id,Name) Values(?,?)"
cmdIns.Connecti on = Con
cmdIns.CommandT ext = sInsSql
Param = cmdIns.Paramete rs.Add("Id", OleDb.OleDbType .Integer)
Param.SourceCol umn = "@Id"
Param.SourceVer sion = DataRowVersion. Current
Param = cmdIns.Paramete rs.Add("Name", OleDb.OleDbType .Char)
Param.SourceCol umn = "@Name"
Param.SourceVer sion = DataRowVersion. Current
adopt.UpdateCom mand = cmdIns
Try
Con.Open()
If Con.State = ConnectionState .Open Then
adopt.MissingSc hemaAction =
MissingSchemaAc tion.AddWithKey
adopt.Fill(ds, "Artist")
Con.Close()
Dim Tables As DataTableCollec tion
Dim Table As DataTable
Dim Cols As DataColumnColle ction
Dim Col As DataColumn
Dim Rows As DataRowCollecti on
Dim Row As DataRow
Tables = ds.Tables
Table = Tables("Artist" )
Rows = Table.Rows
Cols = Table.Columns
Console.WriteLi ne("Original Table Looks Like")
Display(Table)
Console.ReadLin e()
Console.WriteLi ne("Id 1 delete")
Rows.Find(1).De lete()
Console.WriteLi ne("deleted")
Display(Table)
Console.ReadLin e()
Console.WriteLi ne("Id 2 Modify")
Row = Rows.Find(2)
Row.BeginEdit()
Row("Name") = "Mantu"
Row.EndEdit()
Console.WriteLi ne("Updated")
Display(Table)
Console.ReadLin e()
Console.WriteLi ne("Id 1 Add")
Row = Table.NewRow
Row("Id") = 4
Row("Name") = "Deepak"
Rows.Add(Row)
Console.WriteLi ne("Added")
Display(Table)
Console.ReadLin e()
Con.Open()
adopt.Update(ds , "Artist")
Console.WriteLi ne("Done")
End If
Catch ex As Exception
Console.WriteLi ne(ex.ToString)
Console.ReadLin e()
End Try
End Sub
End Module
The Exact error what I got is :
"System.Data.Ol eDb.OleDbExcept ion: Parameter ?_1 has no default value.
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataS et dataSet, String
srcTable)
at ADONetTest.Modu le1.Main() in
D:\Rabi\DotNetP rac\ADONetTest\ ADONetTest\Modu le1.vb:line 176"
This String is generated by "Ex.ToStrin g" 1 2026
This is probably your issue. where is this parameter defined ? sDelSql = "Delete From Artist Where Id = ?"
-----------------------------
The Exact error what I got is :
"System.Data.Ol eDb.OleDbExcept ion: Parameter ?_1 has no default value.
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataS et dataSet, String
srcTable)
at ADONetTest.Modu le1.Main() in
D:\Rabi\DotNetP rac\ADONetTest\ ADONetTest\Modu le1.vb:line 176"
This String is generated by "Ex.ToStrin g"
--
Terry Burns http://TrainingOn.net
"r2destini" <ra************ @gmail.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. . Hi Friends,
I am new to .Net. So I don't know much.
I am facing a problem in updating database through ADO.Net
I am creating the dataset and there is no problem in the updation and deletion or insertion in the dataset but when I am updating the database through adaptor error occures (Coloured Red).
For ref the code follows:
Code:
Imports System.Data.Ole Db Module Module1 Private Const s As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=D:\Rabi\ Database\DBTest-1.mdb;Persist Security Info=False" Public Con As OleDb.OleDbConn ection Public adopt As OleDb.OleDbData Adapter Public ds As DataSet Public sql As String
Dim cmdDel As New OleDb.OleDbComm and, sDelSql As String Dim cmdIns As New OleDb.OleDbComm and, sInsSql As String Dim cmdUpd As New OleDb.OleDbComm and, sUpdSql As String Dim Param As New OleDb.OleDbPara meter
Public Sub Display(ByRef Table As DataTable) Dim row As DataRow Dim col As DataColumn Dim i, j As Integer
For i = 0 To Table.Rows.Coun t - 1 row = Table.Rows(i) Select Case row.RowState Case DataRowState.De leted Console.WriteLi ne("[Deleted]") Case DataRowState.Mo dified Console.WriteLi ne("[Modified]") Case DataRowState.Ad ded Console.WriteLi ne("[Added]") Case DataRowState.Un changed Console.WriteLi ne("[Unchanged]") End Select For j = 0 To Table.Columns.C ount - 1 If row.RowState <> DataRowState.De leted Then Console.WriteLi ne("{0}", row.Item(j)) End If Next Console.WriteLi ne() Next End Sub Public Sub Main() Try Con = New OleDb.OleDbConn ection(s) sql = "Select * from Artist" adopt = New OleDbDataAdapte r(sql, Con) ds = New DataSet Catch ex As Exception Console.WriteLi ne(ex.ToString) Console.ReadLin e() End Try
sDelSql = "Delete From Artist Where Id = ?" cmdDel.Connecti on = Con cmdDel.CommandT ext = sDelSql Param = cmdDel.Paramete rs.Add("Id", OleDb.OleDbType .Integer) Param.SourceCol umn = "@ID" Param.SourceVer sion = DataRowVersion. Original adopt.DeleteCom mand = cmdDel
sUpdSql = "Update Artist Set Name = ? Where Id = ?" cmdUpd.Connecti on = Con cmdUpd.CommandT ext = sUpdSql Param = cmdUpd.Paramete rs.Add("Name", OleDb.OleDbType .Char) Param.SourceCol umn = "@Name" Param.SourceVer sion = DataRowVersion. Current Param = cmdUpd.Paramete rs.Add("Id", OleDb.OleDbType .Integer) Param.SourceCol umn = "@Id" Param.SourceVer sion = DataRowVersion. Original adopt.UpdateCom mand = cmdUpd
sInsSql = "Insert Into Artist (Id,Name) Values(?,?)" cmdIns.Connecti on = Con cmdIns.CommandT ext = sInsSql Param = cmdIns.Paramete rs.Add("Id", OleDb.OleDbType .Integer) Param.SourceCol umn = "@Id" Param.SourceVer sion = DataRowVersion. Current Param = cmdIns.Paramete rs.Add("Name", OleDb.OleDbType .Char) Param.SourceCol umn = "@Name" Param.SourceVer sion = DataRowVersion. Current adopt.UpdateCom mand = cmdIns
Try Con.Open() If Con.State = ConnectionState .Open Then adopt.MissingSc hemaAction = MissingSchemaAc tion.AddWithKey adopt.Fill(ds, "Artist") Con.Close()
Dim Tables As DataTableCollec tion Dim Table As DataTable Dim Cols As DataColumnColle ction Dim Col As DataColumn Dim Rows As DataRowCollecti on Dim Row As DataRow
Tables = ds.Tables Table = Tables("Artist" ) Rows = Table.Rows Cols = Table.Columns
Console.WriteLi ne("Original Table Looks Like") Display(Table) Console.ReadLin e()
Console.WriteLi ne("Id 1 delete") Rows.Find(1).De lete() Console.WriteLi ne("deleted") Display(Table) Console.ReadLin e()
Console.WriteLi ne("Id 2 Modify") Row = Rows.Find(2) Row.BeginEdit() Row("Name") = "Mantu" Row.EndEdit() Console.WriteLi ne("Updated") Display(Table) Console.ReadLin e()
Console.WriteLi ne("Id 1 Add") Row = Table.NewRow Row("Id") = 4 Row("Name") = "Deepak" Rows.Add(Row) Console.WriteLi ne("Added") Display(Table) Console.ReadLin e()
Con.Open() adopt.Update(ds , "Artist") Console.WriteLi ne("Done")
End If Catch ex As Exception Console.WriteLi ne(ex.ToString) Console.ReadLin e() End Try End Sub End Module
The Exact error what I got is :
"System.Data.Ol eDb.OleDbExcept ion: Parameter ?_1 has no default value. at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows, DataTableMappin g tableMapping) at System.Data.Com mon.DbDataAdapt er.Update(DataS et dataSet, String srcTable) at ADONetTest.Modu le1.Main() in D:\Rabi\DotNetP rac\ADONetTest\ ADONetTest\Modu le1.vb:line 176"
This String is generated by "Ex.ToStrin g" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris |
last post by:
A weird issue...though hopefully not for everyone...
I am trying to connect to a 10g database on a Red Hat Linux server from my
9i client on a XP pc.
Both are on my local home network, behind a router.
I can ping the linux server from my XP box successfully:
C:\>ping 192.168.1.101
|
by: Sylesh Nair |
last post by:
could anyone give me a possible solution for a Windows Service (in C#)
listening to a table in a database for insertion or updation.
thanks
|
by: Jeff |
last post by:
IDE: VS 2003 :NET
OS: XP Pro
My app have a form with a tab-control on it. The tab-control have 2
tabpages. One of the tabpages displays a datagrid, and the other tabpage
displays details (order date, name, address etc) about the selected row in
the datagrid...
My problem is when I enter a new record in the details tabpage (saves data...
|
by: r2destini |
last post by:
Hi Friends,
I am new to .Net. So I don't know much.
I am facing a problem in updating database through ADO.Net
I am creating the dataset and there is no problem in the updation and
deletion or insertion in the dataset but when I am updating the
|
by: prashant |
last post by:
Hi,
I am trying to set up Transactional replication with immediate
updation.
The configuration is as follows:
1. Publisher is SQL server 2000 Enterprise Edition, and Distributor is
on the same server.
2. Publisher SQL server is installed on Windows 2003.
| |
by: Usman Jamil |
last post by:
Hi
I've a class that creates a connection to a database, gets and loop on a
dataset given a query and then close the connection. When I use netstat
viewer to see if there is any connection open left, I always see that there
are 2 connections open and in "ESTABLISHED" state. Here is the piece of code
that I'm using, please tell where I'm...
|
by: roshan56us |
last post by:
Hi,
i have problem in updation of access database, which is in backend and Visual basic as front end. its using 800 records in MS-Access but,while updating the database, it doesn't update sometime or sometime it takes two to three times in updation.and sometime application has to be closed and then reopened ,then update. and it get updated.
|
by: siri11 |
last post by:
Hi everyone!!!!!!!!!
If i update a record in a table in sqlserver from front end (c#.net),using a stored procedure for updating then after updation if i open the table then it is showing the same record 2 times i.e before updation record and after updation record..Plzzzzzzzz help me how to solve this problem....its very urgent...Plzzzzzzzzzz
...
|
by: okonita |
last post by:
Hi all,
I am having a DB2 connectivity problem that I hope someone can help me resolve. I need this to test Replication and such other things. What am I doing wrong here? Any help that
I can get will be highly appreciated.
First, the error that I am getting when I try to connect to the remote host after performing NODE and database catalog...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |