473,513 Members | 2,684 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.OleDb
Module Module1
Private Const s As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Rabi\Database\DBTest-1.mdb;Persist Security Info=False"
Public Con As OleDb.OleDbConnection
Public adopt As OleDb.OleDbDataAdapter
Public ds As DataSet
Public sql As String
Dim cmdDel As New OleDb.OleDbCommand, sDelSql As String
Dim cmdIns As New OleDb.OleDbCommand, sInsSql As String
Dim cmdUpd As New OleDb.OleDbCommand, sUpdSql As String
Dim Param As New OleDb.OleDbParameter
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.Count - 1
row = Table.Rows(i)
Select Case row.RowState
Case DataRowState.Deleted
Console.WriteLine("[Deleted]")
Case DataRowState.Modified
Console.WriteLine("[Modified]")
Case DataRowState.Added
Console.WriteLine("[Added]")
Case DataRowState.Unchanged
Console.WriteLine("[Unchanged]")
End Select
For j = 0 To Table.Columns.Count - 1
If row.RowState <> DataRowState.Deleted Then
Console.WriteLine("{0}", row.Item(j))
End If
Next
Console.WriteLine()
Next
End Sub
Public Sub Main()
Try
Con = New OleDb.OleDbConnection(s)
sql = "Select * from Artist"
adopt = New OleDbDataAdapter(sql, Con)
ds = New DataSet
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.ReadLine()
End Try
sDelSql = "Delete From Artist Where Id = ?"
cmdDel.Connection = Con
cmdDel.CommandText = sDelSql
Param = cmdDel.Parameters.Add("Id", OleDb.OleDbType.Integer)
Param.SourceColumn = "@ID"
Param.SourceVersion = DataRowVersion.Original
adopt.DeleteCommand = cmdDel
sUpdSql = "Update Artist Set Name = ? Where Id = ?"
cmdUpd.Connection = Con
cmdUpd.CommandText = sUpdSql
Param = cmdUpd.Parameters.Add("Name", OleDb.OleDbType.Char)
Param.SourceColumn = "@Name"
Param.SourceVersion = DataRowVersion.Current
Param = cmdUpd.Parameters.Add("Id", OleDb.OleDbType.Integer)
Param.SourceColumn = "@Id"
Param.SourceVersion = DataRowVersion.Original
adopt.UpdateCommand = cmdUpd
sInsSql = "Insert Into Artist (Id,Name) Values(?,?)"
cmdIns.Connection = Con
cmdIns.CommandText = sInsSql
Param = cmdIns.Parameters.Add("Id", OleDb.OleDbType.Integer)
Param.SourceColumn = "@Id"
Param.SourceVersion = DataRowVersion.Current
Param = cmdIns.Parameters.Add("Name", OleDb.OleDbType.Char)
Param.SourceColumn = "@Name"
Param.SourceVersion = DataRowVersion.Current
adopt.UpdateCommand = cmdIns
Try
Con.Open()
If Con.State = ConnectionState.Open Then
adopt.MissingSchemaAction =
MissingSchemaAction.AddWithKey
adopt.Fill(ds, "Artist")
Con.Close()
Dim Tables As DataTableCollection
Dim Table As DataTable
Dim Cols As DataColumnCollection
Dim Col As DataColumn
Dim Rows As DataRowCollection
Dim Row As DataRow
Tables = ds.Tables
Table = Tables("Artist")
Rows = Table.Rows
Cols = Table.Columns
Console.WriteLine("Original Table Looks Like")
Display(Table)
Console.ReadLine()
Console.WriteLine("Id 1 delete")
Rows.Find(1).Delete()
Console.WriteLine("deleted")
Display(Table)
Console.ReadLine()
Console.WriteLine("Id 2 Modify")
Row = Rows.Find(2)
Row.BeginEdit()
Row("Name") = "Mantu"
Row.EndEdit()
Console.WriteLine("Updated")
Display(Table)
Console.ReadLine()
Console.WriteLine("Id 1 Add")
Row = Table.NewRow
Row("Id") = 4
Row("Name") = "Deepak"
Rows.Add(Row)
Console.WriteLine("Added")
Display(Table)
Console.ReadLine()
Con.Open()
adopt.Update(ds, "Artist")
Console.WriteLine("Done")
End If
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.ReadLine()
End Try
End Sub
End Module
The Exact error what I got is :
"System.Data.OleDb.OleDbException: Parameter ?_1 has no default value.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at ADONetTest.Module1.Main() in
D:\Rabi\DotNetPrac\ADONetTest\ADONetTest\Module1.v b:line 176"
This String is generated by "Ex.ToString"

Mar 4 '06 #1
1 2024
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.OleDb.OleDbException: Parameter ?_1 has no default value.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at ADONetTest.Module1.Main() in
D:\Rabi\DotNetPrac\ADONetTest\ADONetTest\Module1.v b:line 176"
This String is generated by "Ex.ToString"

--
Terry Burns
http://TrainingOn.net
"r2destini" <ra************@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.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.OleDb
Module Module1
Private Const s As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Rabi\Database\DBTest-1.mdb;Persist Security Info=False"
Public Con As OleDb.OleDbConnection
Public adopt As OleDb.OleDbDataAdapter
Public ds As DataSet
Public sql As String
Dim cmdDel As New OleDb.OleDbCommand, sDelSql As String
Dim cmdIns As New OleDb.OleDbCommand, sInsSql As String
Dim cmdUpd As New OleDb.OleDbCommand, sUpdSql As String
Dim Param As New OleDb.OleDbParameter
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.Count - 1
row = Table.Rows(i)
Select Case row.RowState
Case DataRowState.Deleted
Console.WriteLine("[Deleted]")
Case DataRowState.Modified
Console.WriteLine("[Modified]")
Case DataRowState.Added
Console.WriteLine("[Added]")
Case DataRowState.Unchanged
Console.WriteLine("[Unchanged]")
End Select
For j = 0 To Table.Columns.Count - 1
If row.RowState <> DataRowState.Deleted Then
Console.WriteLine("{0}", row.Item(j))
End If
Next
Console.WriteLine()
Next
End Sub
Public Sub Main()
Try
Con = New OleDb.OleDbConnection(s)
sql = "Select * from Artist"
adopt = New OleDbDataAdapter(sql, Con)
ds = New DataSet
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.ReadLine()
End Try
sDelSql = "Delete From Artist Where Id = ?"
cmdDel.Connection = Con
cmdDel.CommandText = sDelSql
Param = cmdDel.Parameters.Add("Id", OleDb.OleDbType.Integer)
Param.SourceColumn = "@ID"
Param.SourceVersion = DataRowVersion.Original
adopt.DeleteCommand = cmdDel
sUpdSql = "Update Artist Set Name = ? Where Id = ?"
cmdUpd.Connection = Con
cmdUpd.CommandText = sUpdSql
Param = cmdUpd.Parameters.Add("Name", OleDb.OleDbType.Char)
Param.SourceColumn = "@Name"
Param.SourceVersion = DataRowVersion.Current
Param = cmdUpd.Parameters.Add("Id", OleDb.OleDbType.Integer)
Param.SourceColumn = "@Id"
Param.SourceVersion = DataRowVersion.Original
adopt.UpdateCommand = cmdUpd
sInsSql = "Insert Into Artist (Id,Name) Values(?,?)"
cmdIns.Connection = Con
cmdIns.CommandText = sInsSql
Param = cmdIns.Parameters.Add("Id", OleDb.OleDbType.Integer)
Param.SourceColumn = "@Id"
Param.SourceVersion = DataRowVersion.Current
Param = cmdIns.Parameters.Add("Name", OleDb.OleDbType.Char)
Param.SourceColumn = "@Name"
Param.SourceVersion = DataRowVersion.Current
adopt.UpdateCommand = cmdIns
Try
Con.Open()
If Con.State = ConnectionState.Open Then
adopt.MissingSchemaAction =
MissingSchemaAction.AddWithKey
adopt.Fill(ds, "Artist")
Con.Close()
Dim Tables As DataTableCollection
Dim Table As DataTable
Dim Cols As DataColumnCollection
Dim Col As DataColumn
Dim Rows As DataRowCollection
Dim Row As DataRow
Tables = ds.Tables
Table = Tables("Artist")
Rows = Table.Rows
Cols = Table.Columns
Console.WriteLine("Original Table Looks Like")
Display(Table)
Console.ReadLine()
Console.WriteLine("Id 1 delete")
Rows.Find(1).Delete()
Console.WriteLine("deleted")
Display(Table)
Console.ReadLine()
Console.WriteLine("Id 2 Modify")
Row = Rows.Find(2)
Row.BeginEdit()
Row("Name") = "Mantu"
Row.EndEdit()
Console.WriteLine("Updated")
Display(Table)
Console.ReadLine()
Console.WriteLine("Id 1 Add")
Row = Table.NewRow
Row("Id") = 4
Row("Name") = "Deepak"
Rows.Add(Row)
Console.WriteLine("Added")
Display(Table)
Console.ReadLine()
Con.Open()
adopt.Update(ds, "Artist")
Console.WriteLine("Done")
End If
Catch ex As Exception
Console.WriteLine(ex.ToString)
Console.ReadLine()
End Try
End Sub
End Module
The Exact error what I got is :
"System.Data.OleDb.OleDbException: Parameter ?_1 has no default value.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at ADONetTest.Module1.Main() in
D:\Rabi\DotNetPrac\ADONetTest\ADONetTest\Module1.v b:line 176"
This String is generated by "Ex.ToString"

Mar 4 '06 #2

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

Similar topics

2
10482
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...
1
2810
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
2568
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...
0
837
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...
0
1281
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...
5
3368
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...
1
1825
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...
1
1670
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...
0
4517
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...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
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,...
0
7535
jinu1996
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...
1
7098
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...
0
7521
tracyyun
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...
0
5682
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,...
0
3232
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...
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
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...

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.