473,788 Members | 3,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in database updation through Adapter in VB.Net..

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"

Mar 4 '06 #1
1 1828
Hi r2

Correct the following :
1. Replace any @ with "" . when you set SourceColumn there is no need
for @ char
for example : Param.SourceCol umn = "@Id" -- >
Param.SourceCol umn = "Id"
2.You assigned incorrect sqlcommand
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 --- > adopt.InsertCom mand =
cmdIns

After applying this changes, it will work ( i test it )
I hope this help
A.Hadi

Mar 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10515
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
1
2826
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
5
2598
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 to database), and go back to the datagrid. Only the data from the PM-table
1
2039
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
0
1297
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.
5
3399
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 doing it wrong. Since this class is being used at many placed in my actual web based application that...
1
1838
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.
1
1684
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 Thanks in advance siri
1
27117
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts of using databases very well and is prerequisite reading for this article. Frinny’s article explains how to use a SQL Server in your program, but there are other databases as well. Some of them provide .NET connectors, but for those that don’t,...
0
4543
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 is the following: SQL1336N The remote host "WINSVR2008R2-2" was not found. SQLSTATE=08001. I...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.