[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

r2destini

3/4/2006 7:51:00 AM

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.vb:line 176"

This String is generated by "Ex.ToString"

1 Answer

Adm56

7/15/2010 5:33:00 PM

0

On Jul 15, 8:17 am, JediTurtle <jeditur...@yahoo.com> wrote:
> On Jul 14, 10:42 pm, pinballmike217 <weenerman...@aol.com> wrote:
>
>
>
>
>
> > On Jul 14, 7:55 pm, JediTurtle <jeditur...@yahoo.com> wrote:
>
> > > Woo!  Sometimes I forget just how great Cirqus Voltaire really is.
> > > I've been neglecting it a lot lately in favor of the newness of Dredd
> > > and "testing" ST:TNG since it's shop job (finally have all the opto
> > > gremlins out I think).  Tonight I just felt like firing it up, and wow
> > > am I glad I did.
>
> > > I had an epic fight with the Ringmaster, culminating in a winning
> > > final battle.  I've done this before, but very rarely and it's always
> > > a treat.  The animation/celebration sequence is amazing (and friggin
> > > scary the first time you hit it!!)!
>
> > > Then I joined the circus...another thing I've done quite a bit before,
> > > but I don't think I ever have after battling the RM.  Then the
> > > unthinkable...I actually got through the second level (Unmask
> > > Voltaire) which I almost always choke on.  Then even more
> > > unthinkable..through the 3rd level and on to Party Multiball!  I've
> > > only seen the Party a handful of times.  What a treat!  Once that
> > > ended I still had one extra ball and was able to get almost half way
> > > back to the circus...but alas a second join (which I've NEVER done)
> > > was not in the cards.  But...the combo of the Battle and the Party
> > > absolutely smoked my old Grand Champion score, and I ended up with
> > > just shy of 154m.  I'm sure most of you have done way better than
> > > that, but for me that's a lot!  My old GC was in the 120m range.
>
> > > Boy, after a pretty rough day, that was just what the doctor ordered!
> > > I'm actually exhausted after that game!  Few things can brighten your
> > > day like bashing the old Ringmaster's head in!
>
> > > I hope you all have a great game as well tonight! :)
> > > Chris
>
> >   Well done. CV is a treat to own. Don't ever sell a CV until you've
> > seen all it has to offer, and that can take a very long time.
>
> > Mike- Hide quoted text -
>
> > - Show quoted text -
>
> Yea, every time I hear someone talk about CV being shallow I have to
> wonder if they've really seen it all.  Sure, it's not all that
> difficult to get TO the wizard mode, but getting through it is another
> ball game.  Not to even mention getting through it a second time for
> the extra levels.  Plus RM Battle which is like a secondary wizard
> mode of it's own, but you can just as easily skip it if you don't feel
> like bashing the ringmaster anymore.  That battle sure gets the
> adrenaline pumping though.  I love how he taunts you and the timed
> aspect.  Make the shots quickly, or you are toast and the flippers go
> dead.  Awesome programming.
>
> I still can't believe I briefly considered trading CV away...boy I'm
> glad I came to my senses on that one!- Hide quoted text -
>
> - Show quoted text -

Honestly I think the RM gets a bit of a bad rap….for a bash toy I
think it actually provides a fair amount of variety (Certainly more
than say Iron Monger in IM and everyone seems to love him!).

Sure when he’s at mid level you just bash him, but when he rises up
you actually have to aim a little bit because shots can hit the spring
and bounce out or loop through the WOW area and shoot out as well.
Then you add the fun effects of him slinging the ball (if you allow
that in the menu…some folks don’t….I actually get very few stuck balls
despite not having all the upgrade kits installed) and of course the
RM Battle mode.

Maybe things would be different if I was a better player, but at my
current skill level it’s great fun to shoot shots down his throat
during Frenzy and Razz…just something satisfying about the ball
clanking down in there…sort of like Dr. Who’s MPF gates…