473,558 Members | 2,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New columns and update problem...!

I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As
String) that creates a new oledbDataAdapte r with insert update select and
delete commads. I also added that commands can change depending how many
columns are in a Table.
I add a new column with this code:

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Try
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Add("TEST
Marko", GetType(Integer ))
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Accep tChanges()
Form2.Table1Dat aGridView.AutoG enerateColumns = True
Novo(Form2.Stud enti1Data.Table s.Item(Index(Co mboBox1.Text)). TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exc lamation, "Upozorenje !")
End Try

End Sub
Function index() gets the index of the Table. The column shows in the
datagridview but whe I try
to save changes I get this exception:
System.Data.Ole Db.OleDbExcepti on was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microso ft JET Database Engine"
StackTrace:
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atusErrors(RowU pdatedEventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atus(RowUpdated EventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.UpdateFromDa taTable(DataTab le
dataTable, DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 305
at Diplomski1.Form 2.Table1Binding NavigatorSaveIt em_Click(Object
sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm2.vb:line 8
at System.Windows. Forms.ToolStrip Item.RaiseEvent (Object key,
EventArgs e)
at System.Windows. Forms.ToolStrip Button.OnClick( EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleClic k(EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleMous eUp(MouseEventA rgs e)
at System.Windows. Forms.ToolStrip Item.FireEventI nteractive(Even tArgs
e, ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip Item.FireEvent( EventArgs e,
ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip .OnMouseUp(Mous eEventArgs mea)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.ToolStrip .WndProc(Messag e& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
Procedur for the oledbDataAdapte r is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbConn ection(Global.D iplomski1.My.My Settings.Defaul t.Studenti1Conn ection)
Dim SelectCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim UpdateCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim InsertCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim DeleteCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Com mon.DataTableMa pping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
tableMapping.Co lumnMappings.Ad d(Form2.Student i1Data.Tables.I tem(Index(Combo Box1.Text)).Col umns.Item(i).Co lumnName,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i
nova.TableMappi ngs.Add(tableMa pping)
nova.MissingMap pingAction = MissingMappingA ction.Passthrou gh
nova.MissingSch emaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptChan gesDuringUpdate = True
SelectCom.Conne ction = veza
SelectCom.Comma ndType = CommandType.Tex t
SelectCom.Comma ndText = "SELECT * FROM " & nova1
UpdateCom.Conne ction = veza
UpdateCom.Comma ndType = CommandType.Tex t
UpdateCom.Comma ndText = "UPDATE " & nova1 & " SET " & InsSql(ComboBox 1.Text,
"Treci") & " WHERE [Broj iksice]=?" '[Broj iksice]=?, [Prezime]=?, [Ime]=?,
[Broj indeksa]=?, [Broj pohadjanja]=? & _
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Current, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion. Current, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion. Current, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Current, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion. Current, False,
Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
UpdateCom.Param eters.Add(New
OleDb.OleDbPara meter(Form2.Stu denti1Data.Tabl es.Item(Index(C omboBox1.Text)) .Columns.Item(i ).ColumnName,
_
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
DataRowVersion. Current, False, Nothing))
Next i
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Original, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Prezime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion. Original, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion. Original, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Original, True,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion. Original, True,
Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari " &
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
_
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
DataRowVersion. Original, True, Nothing))
Next i
InsertCom.Conne ction = veza
InsertCom.Comma ndType = CommandType.Tex t
InsertCom.Comma ndText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox 1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox 1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime], [Ime],
[Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Param eters.Add("Broj iksice", OleDb.OleDbType .Double, 0, "Broj
iksice")
InsertCom.Param eters.Add("Prez ime", OleDb.OleDbType .WChar, 0, "Prezime")
InsertCom.Param eters.Add("Ime" , OleDb.OleDbType .WChar, 0, "Ime")
InsertCom.Param eters.Add("Broj indeksa", OleDb.OleDbType .WChar, 0, "Broj
indeksa")
InsertCom.Param eters.Add("Broj pohadjanja", OleDb.OleDbType .Integer, 0,
"Broj pohadjanja")
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
InsertCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)).Columns.It em(i).ColumnNam e,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i
DeleteCom.Conne ction = veza
DeleteCom.Comma ndType = CommandType.Tex t
DeleteCom.Comma ndText = "DELETE * FROM " & nova1 & " WHERE [Broj iksice]=?"
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, False,
CType(20, Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Original, Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion. Original,
Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
DeleteCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)).Columns.It em(i).ColumnNam e,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i

nova.SelectComm and = SelectCom
nova.UpdateComm and = UpdateCom
nova.DeleteComm and = DeleteCom
nova.InsertComm and = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)))
End If
If nova2 = "Update" Then
nova.Update(For m2.Studenti1Dat a.Tables.Item(I ndex(ComboBox1. Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox 1.Text, string) creates new sql commands with new column. The
code is:
Public Function InsSql(ByVal imeTab As String, ByVal tipSql As String) As
String 'Generira nastavak sql komande za update i insert
Dim i As Integer
Dim sql As String = "[Broj iksice]"
If tipSql = "Prvi" Then
For i = 1 To Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count -
1
sql = sql & ", [" &
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Item( i).ColumnName &
"]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count -
2
sql = sql & ", ?" 'Ove dvije if petlje za insert komandu
Next i
End If
If tipSql = "Treci" Then
sql = "[Broj iksice]=?"
For i = 1 To Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count -
1
sql = sql & ", [" &
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Item( i).ColumnName &
"]" & "=?" 'Za Update komandu
Next i
End If
Return sql
End Function

Dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource draging Table1 to Form2. I
use Access database.
Please help....!
Jan 23 '07 #1
5 2151
Explode,

Do you really believe that there is one person on earth who will have a look
at your code.

If you want help, than make a simple sample from absolute no more than 20
lines.

Cor

"explode" <ur**@mzos.hrsc hreef in bericht
news:ep******** **@news1.carnet .hr...
>I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As
String) that creates a new oledbDataAdapte r with insert update select and
delete commads. I also added that commands can change depending how many
columns are in a Table.
I add a new column with this code:

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Try
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Add("TEST
Marko", GetType(Integer ))
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Accep tChanges()
Form2.Table1Dat aGridView.AutoG enerateColumns = True
Novo(Form2.Stud enti1Data.Table s.Item(Index(Co mboBox1.Text)). TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exc lamation, "Upozorenje !")
End Try

End Sub
Function index() gets the index of the Table. The column shows in the
datagridview but whe I try
to save changes I get this exception:
System.Data.Ole Db.OleDbExcepti on was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microso ft JET Database Engine"
StackTrace:
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atusErrors(RowU pdatedEventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atus(RowUpdated EventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.UpdateFromDa taTable(DataTab le
dataTable, DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 305
at Diplomski1.Form 2.Table1Binding NavigatorSaveIt em_Click(Object
sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm2.vb:line 8
at System.Windows. Forms.ToolStrip Item.RaiseEvent (Object key,
EventArgs e)
at System.Windows. Forms.ToolStrip Button.OnClick( EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleClic k(EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleMous eUp(MouseEventA rgs
e)
at System.Windows. Forms.ToolStrip Item.FireEventI nteractive(Even tArgs
e, ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip Item.FireEvent( EventArgs e,
ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip .OnMouseUp(Mous eEventArgs mea)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons
button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.ToolStrip .WndProc(Messag e& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage&
m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
Procedur for the oledbDataAdapte r is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbConn ection(Global.D iplomski1.My.My Settings.Defaul t.Studenti1Conn ection)
Dim SelectCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim UpdateCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim InsertCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim DeleteCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Com mon.DataTableMa pping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
tableMapping.Co lumnMappings.Ad d(Form2.Student i1Data.Tables.I tem(Index(Combo Box1.Text)).Col umns.Item(i).Co lumnName,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i
nova.TableMappi ngs.Add(tableMa pping)
nova.MissingMap pingAction = MissingMappingA ction.Passthrou gh
nova.MissingSch emaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptChan gesDuringUpdate = True
SelectCom.Conne ction = veza
SelectCom.Comma ndType = CommandType.Tex t
SelectCom.Comma ndText = "SELECT * FROM " & nova1
UpdateCom.Conne ction = veza
UpdateCom.Comma ndType = CommandType.Tex t
UpdateCom.Comma ndText = "UPDATE " & nova1 & " SET " &
InsSql(ComboBox 1.Text, "Treci") & " WHERE [Broj iksice]=?" '[Broj
iksice]=?, [Prezime]=?, [Ime]=?, [Broj indeksa]=?, [Broj pohadjanja]=? & _
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Current, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion. Current, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion. Current, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Current, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion. Current, False,
Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
UpdateCom.Param eters.Add(New
OleDb.OleDbPara meter(Form2.Stu denti1Data.Tabl es.Item(Index(C omboBox1.Text)) .Columns.Item(i ).ColumnName,
_
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
DataRowVersion. Current, False, Nothing))
Next i
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Original, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Prezime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion. Original, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion. Original, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Original, True,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion. Original, True,
Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari " &
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
_
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
DataRowVersion. Original, True, Nothing))
Next i
InsertCom.Conne ction = veza
InsertCom.Comma ndType = CommandType.Tex t
InsertCom.Comma ndText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox 1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox 1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime], [Ime],
[Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Param eters.Add("Broj iksice", OleDb.OleDbType .Double, 0, "Broj
iksice")
InsertCom.Param eters.Add("Prez ime", OleDb.OleDbType .WChar, 0, "Prezime")
InsertCom.Param eters.Add("Ime" , OleDb.OleDbType .WChar, 0, "Ime")
InsertCom.Param eters.Add("Broj indeksa", OleDb.OleDbType .WChar, 0, "Broj
indeksa")
InsertCom.Param eters.Add("Broj pohadjanja", OleDb.OleDbType .Integer, 0,
"Broj pohadjanja")
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
InsertCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)).Columns.It em(i).ColumnNam e,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i
DeleteCom.Conne ction = veza
DeleteCom.Comma ndType = CommandType.Tex t
DeleteCom.Comma ndText = "DELETE * FROM " & nova1 & " WHERE [Broj
iksice]=?"
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input, False,
CType(20, Byte), CType(0, Byte), "Broj iksice", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Original, Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion. Original, Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count - 1
DeleteCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)).Columns.It em(i).ColumnNam e,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i

nova.SelectComm and = SelectCom
nova.UpdateComm and = UpdateCom
nova.DeleteComm and = DeleteCom
nova.InsertComm and = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)))
End If
If nova2 = "Update" Then
nova.Update(For m2.Studenti1Dat a.Tables.Item(I ndex(ComboBox1. Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox 1.Text, string) creates new sql commands with new column.
The code is:
Public Function InsSql(ByVal imeTab As String, ByVal tipSql As String) As
String 'Generira nastavak sql komande za update i insert
Dim i As Integer
Dim sql As String = "[Broj iksice]"
If tipSql = "Prvi" Then
For i = 1 To
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count - 1
sql = sql & ", [" &
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Item( i).ColumnName
& "]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count - 2
sql = sql & ", ?" 'Ove dvije if petlje za insert komandu
Next i
End If
If tipSql = "Treci" Then
sql = "[Broj iksice]=?"
For i = 1 To
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count - 1
sql = sql & ", [" &
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Item( i).ColumnName
& "]" & "=?" 'Za Update komandu
Next i
End If
Return sql
End Function

Dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource draging Table1 to Form2. I
use Access database.
Please help....!

Jan 23 '07 #2
This is your primary error:
Message="Cannot update 'TEST Marko'; field not updateable."
Is the field an AutoNumber field? If so, you can not update it.

Robin S.

-----------------------------------
"explode" <ur**@mzos.hrwr ote in message
news:ep******** **@news1.carnet .hr...
>I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2
As String) that creates a new oledbDataAdapte r with insert update
select and delete commads. I also added that commands can change
depending how many columns are in a Table.
I add a new column with this code:

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Try
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Add("TEST
Marko", GetType(Integer ))
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Accep tChanges()
Form2.Table1Dat aGridView.AutoG enerateColumns = True
Novo(Form2.Stud enti1Data.Table s.Item(Index(Co mboBox1.Text)). TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exc lamation,
"Upozorenje !")
End Try

End Sub
Function index() gets the index of the Table. The column shows in the
datagridview but whe I try
to save changes I get this exception:
System.Data.Ole Db.OleDbExcepti on was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microso ft JET Database Engine"
StackTrace:
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atusErrors(RowU pdatedEventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at
System.Data.Com mon.DbDataAdapt er.UpdatedRowSt atus(RowUpdated EventArgs
rowUpdatedEvent , BatchCommandInf o[] batchCommands, Int32 commandCount)
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappin g tableMapping)
at
System.Data.Com mon.DbDataAdapt er.UpdateFromDa taTable(DataTab le
dataTable, DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm1.vb:line 305
at Diplomski1.Form 2.Table1Binding NavigatorSaveIt em_Click(Object
sender, EventArgs e) in
D:\OdMomka\Dipl omski\Diplomski 1\Diplomski1\Fo rm2.vb:line 8
at System.Windows. Forms.ToolStrip Item.RaiseEvent (Object key,
EventArgs e)
at System.Windows. Forms.ToolStrip Button.OnClick( EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleClic k(EventArgs e)
at
System.Windows. Forms.ToolStrip Item.HandleMous eUp(MouseEventA rgs e)
at
System.Windows. Forms.ToolStrip Item.FireEventI nteractive(Even tArgs e,
ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip Item.FireEvent( EventArgs e,
ToolStripItemEv entType met)
at System.Windows. Forms.ToolStrip .OnMouseUp(Mous eEventArgs mea)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.ToolStrip .WndProc(Messag e& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Applicati on.ComponentMan ager.System.Win dows.Forms.Unsa feNativeMethods .IMsoComponentM anager.FPushMes sageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext
context)
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.OnRun ()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.DoApp licationModel()
at
Microsoft.Visua lBasic.Applicat ionServices.Win dowsFormsApplic ationBase.Run(S tring[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[]
args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean
checkAptModel)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt, String[] activationCusto mData)
at
System.Runtime. Hosting.Applica tionActivator.C reateInstance(A ctivationContex t
activationConte xt)
at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem blyDebugInZone( )
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
Procedur for the oledbDataAdapte r is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbConn ection(Global.D iplomski1.My.My Settings.Defaul t.Studenti1Conn ection)
Dim SelectCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim UpdateCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim InsertCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim DeleteCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Com mon.DataTableMa pping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count -
1
tableMapping.Co lumnMappings.Ad d(Form2.Student i1Data.Tables.I tem(Index(Combo Box1.Text)).Col umns.Item(i).Co lumnName,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i
nova.TableMappi ngs.Add(tableMa pping)
nova.MissingMap pingAction = MissingMappingA ction.Passthrou gh
nova.MissingSch emaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptChan gesDuringUpdate = True
SelectCom.Conne ction = veza
SelectCom.Comma ndType = CommandType.Tex t
SelectCom.Comma ndText = "SELECT * FROM " & nova1
UpdateCom.Conne ction = veza
UpdateCom.Comma ndType = CommandType.Tex t
UpdateCom.Comma ndText = "UPDATE " & nova1 & " SET " &
InsSql(ComboBox 1.Text, "Treci") & " WHERE [Broj iksice]=?" '[Broj
iksice]=?, [Prezime]=?, [Ime]=?, [Broj indeksa]=?, [Broj pohadjanja]=?
& _
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input,
CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion. Current, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Current,
False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Current, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion. Current, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion. Current, False, Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count -
1
UpdateCom.Param eters.Add(New
OleDb.OleDbPara meter(Form2.Stu denti1Data.Tabl es.Item(Index(C omboBox1.Text)) .Columns.Item(i ).ColumnName,
_
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
DataRowVersion. Current, False, Nothing))
Next i
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input,
CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion. Original, False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Prezime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Original,
False, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Original, False,
Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj
indeksa", OleDb.OleDbType .WChar, 0,
System.Data.Par ameterDirection .Input, CType(0, Byte), CType(0, Byte),
"Broj indeksa", DataRowVersion. Original, True, Nothing))
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari Broj
pohadjanja", OleDb.OleDbType .Integer, 0,
System.Data.Par ameterDirection .Input, CType(0, Byte), CType(0, Byte),
"Broj pohadjanja", DataRowVersion. Original, True, Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count -
1
UpdateCom.Param eters.Add(New OleDb.OleDbPara meter("stari " &
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
_
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName,
DataRowVersion. Original, True, Nothing))
Next i
InsertCom.Conne ction = veza
InsertCom.Comma ndType = CommandType.Tex t
InsertCom.Comma ndText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox 1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox 1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime],
[Ime], [Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Param eters.Add("Broj iksice", OleDb.OleDbType .Double, 0,
"Broj iksice")
InsertCom.Param eters.Add("Prez ime", OleDb.OleDbType .WChar, 0,
"Prezime")
InsertCom.Param eters.Add("Ime" , OleDb.OleDbType .WChar, 0, "Ime")
InsertCom.Param eters.Add("Broj indeksa", OleDb.OleDbType .WChar, 0,
"Broj indeksa")
InsertCom.Param eters.Add("Broj pohadjanja", OleDb.OleDbType .Integer,
0, "Broj pohadjanja")
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count -
1
InsertCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)).Columns.It em(i).ColumnNam e,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i
DeleteCom.Conne ction = veza
DeleteCom.Comma ndType = CommandType.Tex t
DeleteCom.Comma ndText = "DELETE * FROM " & nova1 & " WHERE [Broj
iksice]=?"
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbType .Double, 0, System.Data.Par ameterDirection .Input,
False, CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion. Original, Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Original,
Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbType .WChar, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion. Original, Nothing))
DeleteCom.Param eters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbType .Integer, 0, System.Data.Par ameterDirection .Input,
True, CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion. Original, Nothing))
For i = 5 To
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Count -
1
DeleteCom.Param eters.Add(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)).Columns.It em(i).ColumnNam e,
_
OleDb.OleDbType .Integer, 0,
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Item(i).Colu mnName)
Next i

nova.SelectComm and = SelectCom
nova.UpdateComm and = UpdateCom
nova.DeleteComm and = DeleteCom
nova.InsertComm and = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2 .Studenti1Data. Tables.Item(Ind ex(ComboBox1.Te xt)))
End If
If nova2 = "Update" Then
nova.Update(For m2.Studenti1Dat a.Tables.Item(I ndex(ComboBox1. Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox 1.Text, string) creates new sql commands with new
column. The code is:
Public Function InsSql(ByVal imeTab As String, ByVal tipSql As String)
As String 'Generira nastavak sql komande za update i insert
Dim i As Integer
Dim sql As String = "[Broj iksice]"
If tipSql = "Prvi" Then
For i = 1 To
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count - 1
sql = sql & ", [" &
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Item( i).ColumnName
& "]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count - 2
sql = sql & ", ?" 'Ove dvije if petlje za insert komandu
Next i
End If
If tipSql = "Treci" Then
sql = "[Broj iksice]=?"
For i = 1 To
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Count - 1
sql = sql & ", [" &
Form2.Studenti1 Data.Tables.Ite m(Index(imeTab) ).Columns.Item( i).ColumnName
& "]" & "=?" 'Za Update komandu
Next i
End If
Return sql
End Function

Dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource draging Table1 to
Form2. I use Access database.
Please help....!

Jan 23 '07 #3
Apparently there is *one*. But in all fairness, I didn't scrutinize it
that closely. A little dizzying, isn't it?

Robin S.
-----------------------------------------

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:Ov******** ******@TK2MSFTN GP05.phx.gbl...
Explode,

Do you really believe that there is one person on earth who will have
a look at your code.

If you want help, than make a simple sample from absolute no more than
20 lines.

Cor

"explode" <ur**@mzos.hrsc hreef in bericht
news:ep******** **@news1.carnet .hr...
>>I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2
As String) that creates a new oledbDataAdapte r with insert update
select and delete commads. I also added that commands can change
depending how many columns are in a Table.
I add a new column with this code:

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles Button4.Click
Try
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Add("TEST
Marko", GetType(Integer ))
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Acce ptChanges()
Form2.Table1Da taGridView.Auto GenerateColumns = True
Novo(Form2.Stu denti1Data.Tabl es.Item(Index(C omboBox1.Text)) .TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exc lamation,
"Upozorenje! ")
End Try

End Sub
Function index() gets the index of the Table. The column shows in the
datagridview but whe I try
to save changes I get this exception:
System.Data.Ol eDb.OleDbExcept ion was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microso ft JET Database Engine"
StackTrace:
at
System.Data.Co mmon.DbDataAdap ter.UpdatedRowS tatusErrors(Row UpdatedEventArg s
rowUpdatedEven t, BatchCommandInf o[] batchCommands, Int32
commandCount )
at
System.Data.Co mmon.DbDataAdap ter.UpdatedRowS tatus(RowUpdate dEventArgs
rowUpdatedEven t, BatchCommandInf o[] batchCommands, Int32
commandCount )
at System.Data.Com mon.DbDataAdapt er.Update(DataR ow[] dataRows,
DataTableMappi ng tableMapping)
at
System.Data.Co mmon.DbDataAdap ter.UpdateFromD ataTable(DataTa ble
dataTable, DataTableMappin g tableMapping)
at System.Data.Com mon.DbDataAdapt er.Update(DataT able dataTable)
at Diplomski1.Form 1.Novo(String nova1, String nova2) in
D:\OdMomka\Dip lomski\Diplomsk i1\Diplomski1\F orm1.vb:line 305
at Diplomski1.Form 2.Table1Binding NavigatorSaveIt em_Click(Object
sender, EventArgs e) in
D:\OdMomka\Dip lomski\Diplomsk i1\Diplomski1\F orm2.vb:line 8
at System.Windows. Forms.ToolStrip Item.RaiseEvent (Object key,
EventArgs e)
at System.Windows. Forms.ToolStrip Button.OnClick( EventArgs e)
at System.Windows. Forms.ToolStrip Item.HandleClic k(EventArgs e)
at
System.Windows .Forms.ToolStri pItem.HandleMou seUp(MouseEvent Args e)
at
System.Windows .Forms.ToolStri pItem.FireEvent Interactive(Eve ntArgs e,
ToolStripItemE ventType met)
at System.Windows. Forms.ToolStrip Item.FireEvent( EventArgs e,
ToolStripItemE ventType met)
at System.Windows. Forms.ToolStrip .OnMouseUp(Mous eEventArgs mea)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m,
MouseButtons button, Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.ToolStrip .WndProc(Messag e& m)
at
System.Windows .Forms.Control. ControlNativeWi ndow.OnMessage( Message&
m)
at
System.Windows .Forms.Control. ControlNativeWi ndow.WndProc(Me ssage& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows .Forms.UnsafeNa tiveMethods.Dis patchMessageW(M SG& msg)
at
System.Windows .Forms.Applicat ion.ComponentMa nager.System.Wi ndows.Forms.Uns afeNativeMethod s.IMsoComponent Manager.FPushMe ssageLoop(Int32
dwComponentI D, Int32 reason, Int32 pvLoopData)
at
System.Windows .Forms.Applicat ion.ThreadConte xt.RunMessageLo opInner(Int32
reason, ApplicationCont ext context)
at
System.Windows .Forms.Applicat ion.ThreadConte xt.RunMessageLo op(Int32
reason, ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Applicat ionContext
context)
at
Microsoft.Visu alBasic.Applica tionServices.Wi ndowsFormsAppli cationBase.OnRu n()
at
Microsoft.Visu alBasic.Applica tionServices.Wi ndowsFormsAppli cationBase.DoAp plicationModel( )
at
Microsoft.Visu alBasic.Applica tionServices.Wi ndowsFormsAppli cationBase.Run( String[]
commandLine)
at Diplomski1.My.M yApplication.Ma in(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.v b:line 81
at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
at System.Runtime. Hosting.Manifes tRunner.Run(Boo lean
checkAptMode l)
at System.Runtime. Hosting.Manifes tRunner.Execute AsAssembly()
at
System.Runtime .Hosting.Applic ationActivator. CreateInstance( ActivationConte xt
activationCont ext, String[] activationCusto mData)
at
System.Runtime .Hosting.Applic ationActivator. CreateInstance( ActivationConte xt
activationCont ext)
at
Microsoft.Visu alStudio.Hostin gProcess.HostPr oc.RunUsersAsse mblyDebugInZone ()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionConte xt, ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()
Procedur for the oledbDataAdapte r is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbData Adapter = New OleDb.OleDbData Adapter
Dim veza As OleDb.OleDbConn ection = New
OleDb.OleDbCon nection(Global. Diplomski1.My.M ySettings.Defau lt.Studenti1Con nection)
Dim SelectCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim UpdateCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim InsertCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim DeleteCom As OleDb.OleDbComm and = New OleDb.OleDbComm and
Dim tableMapping As System.Data.Com mon.DataTableMa pping = New
System.Data.Co mmon.DataTableM apping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Count
- 1
tableMapping.C olumnMappings.A dd(Form2.Studen ti1Data.Tables. Item(Index(Comb oBox1.Text)).Co lumns.Item(i).C olumnName,
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Item(i).Col umnName)
Next i
nova.TableMapp ings.Add(tableM apping)
nova.MissingMa ppingAction = MissingMappingA ction.Passthrou gh
nova.MissingSc hemaAction = MissingSchemaAc tion.AddWithKey
nova.AcceptCha ngesDuringUpdat e = True
SelectCom.Conn ection = veza
SelectCom.Comm andType = CommandType.Tex t
SelectCom.Comm andText = "SELECT * FROM " & nova1
UpdateCom.Conn ection = veza
UpdateCom.Comm andType = CommandType.Tex t
UpdateCom.Comm andText = "UPDATE " & nova1 & " SET " &
InsSql(ComboBo x1.Text, "Treci") & " WHERE [Broj iksice]=?" '[Broj
iksice]=?, [Prezime]=?, [Ime]=?, [Broj indeksa]=?, [Broj
pohadjanja]=? & _
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbTyp e.Double, 0, System.Data.Par ameterDirection .Input,
CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion .Current, False, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Current,
False, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Current, False,
Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion .Current, False, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbTyp e.Integer, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion .Current, False, Nothing))
For i = 5 To
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Count
- 1
UpdateCom.Para meters.Add(New
OleDb.OleDbPar ameter(Form2.St udenti1Data.Tab les.Item(Index( ComboBox1.Text) ).Columns.Item( i).ColumnName,
_
OleDb.OleDbTyp e.Integer, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Item(i).Col umnName,
DataRowVersion .Current, False, Nothing))
Next i
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("stari Broj
iksice", OleDb.OleDbType .Double, 0,
System.Data.Pa rameterDirectio n.Input, CType(20, Byte), CType(0,
Byte), "Broj iksice", DataRowVersion. Original, False, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("stari Prezime",
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion. Original,
False, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("stari Ime",
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion. Original,
False, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("stari Broj
indeksa", OleDb.OleDbType .WChar, 0,
System.Data.Pa rameterDirectio n.Input, CType(0, Byte), CType(0, Byte),
"Broj indeksa", DataRowVersion. Original, True, Nothing))
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("stari Broj
pohadjanja", OleDb.OleDbType .Integer, 0,
System.Data.Pa rameterDirectio n.Input, CType(0, Byte), CType(0, Byte),
"Broj pohadjanja", DataRowVersion. Original, True, Nothing))
For i = 5 To
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Count
- 1
UpdateCom.Para meters.Add(New OleDb.OleDbPara meter("stari " &
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Item(i).Col umnName,
_
OleDb.OleDbTyp e.Integer, 0, System.Data.Par ameterDirection .Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Item(i).Col umnName,
DataRowVersion .Original, True, Nothing))
Next i
InsertCom.Conn ection = veza
InsertCom.Comm andType = CommandType.Tex t
InsertCom.Comm andText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBo x1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBo x1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime],
[Ime], [Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Para meters.Add("Bro j iksice", OleDb.OleDbType .Double, 0,
"Broj iksice")
InsertCom.Para meters.Add("Pre zime", OleDb.OleDbType .WChar, 0,
"Prezime")
InsertCom.Para meters.Add("Ime ", OleDb.OleDbType .WChar, 0, "Ime")
InsertCom.Para meters.Add("Bro j indeksa", OleDb.OleDbType .WChar, 0,
"Broj indeksa")
InsertCom.Para meters.Add("Bro j pohadjanja", OleDb.OleDbType .Integer,
0, "Broj pohadjanja")
For i = 5 To
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Count
- 1
InsertCom.Para meters.Add(Form 2.Studenti1Data .Tables.Item(In dex(ComboBox1.T ext)).Columns.I tem(i).ColumnNa me,
_
OleDb.OleDbTyp e.Integer, 0,
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Item(i).Col umnName)
Next i
DeleteCom.Conn ection = veza
DeleteCom.Comm andType = CommandType.Tex t
DeleteCom.Comm andText = "DELETE * FROM " & nova1 & " WHERE [Broj
iksice]=?"
DeleteCom.Para meters.Add(New OleDb.OleDbPara meter("Broj iksice",
OleDb.OleDbTyp e.Double, 0, System.Data.Par ameterDirection .Input,
False, CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion .Original, Nothing))
DeleteCom.Para meters.Add(New OleDb.OleDbPara meter("Prezime" ,
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "Prezime",
DataRowVersion .Original, Nothing))
DeleteCom.Para meters.Add(New OleDb.OleDbPara meter("Ime",
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input,
False, CType(0, Byte), CType(0, Byte), "Ime",
DataRowVersion .Original, Nothing))
DeleteCom.Para meters.Add(New OleDb.OleDbPara meter("Broj indeksa",
OleDb.OleDbTyp e.WChar, 0, System.Data.Par ameterDirection .Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion .Original, Nothing))
DeleteCom.Para meters.Add(New OleDb.OleDbPara meter("Broj pohadjanja",
OleDb.OleDbTyp e.Integer, 0, System.Data.Par ameterDirection .Input,
True, CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion .Original, Nothing))
For i = 5 To
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Count
- 1
DeleteCom.Para meters.Add(Form 2.Studenti1Data .Tables.Item(In dex(ComboBox1.T ext)).Columns.I tem(i).ColumnNa me,
_
OleDb.OleDbTyp e.Integer, 0,
Form2.Studenti 1Data.Tables.It em(Index(ComboB ox1.Text)).Colu mns.Item(i).Col umnName)
Next i

nova.SelectCom mand = SelectCom
nova.UpdateCom mand = UpdateCom
nova.DeleteCom mand = DeleteCom
nova.InsertCom mand = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form 2.Studenti1Data .Tables.Item(In dex(ComboBox1.T ext)))
End If
If nova2 = "Update" Then
nova.Update(Fo rm2.Studenti1Da ta.Tables.Item( Index(ComboBox1 .Text)))
End If
veza.Close()
End Sub
InsSql(ComboBo x1.Text, string) creates new sql commands with new
column. The code is:
Public Function InsSql(ByVal imeTab As String, ByVal tipSql As
String) As String 'Generira nastavak sql komande za update i insert
Dim i As Integer
Dim sql As String = "[Broj iksice]"
If tipSql = "Prvi" Then
For i = 1 To
Form2.Studenti 1Data.Tables.It em(Index(imeTab )).Columns.Coun t - 1
sql = sql & ", [" &
Form2.Studenti 1Data.Tables.It em(Index(imeTab )).Columns.Item (i).ColumnName
& "]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To
Form2.Studenti 1Data.Tables.It em(Index(imeTab )).Columns.Coun t - 2
sql = sql & ", ?" 'Ove dvije if petlje za insert komandu
Next i
End If
If tipSql = "Treci" Then
sql = "[Broj iksice]=?"
For i = 1 To
Form2.Studenti 1Data.Tables.It em(Index(imeTab )).Columns.Coun t - 1
sql = sql & ", [" &
Form2.Studenti 1Data.Tables.It em(Index(imeTab )).Columns.Item (i).ColumnName
& "]" & "=?" 'Za Update komandu
Next i
End If
Return sql
End Function

Dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource draging Table1 to
Form2. I use Access database.
Please help....!


Jan 23 '07 #4
My table has 5 columns: Broj iksice, Prezime, Ime, Broj indeksa, Broj
pohadjanja.
This is the code in the dataset designer VB made it by it self:

Private Sub InitClass()
Me.columnBroj_i ksice = New System.Data.Dat aColumn("Broj iksice",
GetType(Double) , Nothing, System.Data.Map pingType.Elemen t)
Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_Colum nPropNameInRow" ,
"Broj_iksic e")
Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_Colum nPropNameInTabl e",
"Broj_iksiceCol umn")
Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_Colum nVarNameInTable ",
"columnBroj_iks ice")
Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_UserC olumnName",
"Broj iksice")
MyBase.Columns. Add(Me.columnBr oj_iksice)
Me.columnPrezim e = New System.Data.Dat aColumn("Prezim e",
GetType(String) , Nothing, System.Data.Map pingType.Elemen t)
MyBase.Columns. Add(Me.columnPr ezime)
Me.columnIme = New System.Data.Dat aColumn("Ime",
GetType(String) , Nothing, System.Data.Map pingType.Elemen t)
MyBase.Columns. Add(Me.columnIm e)
Me.columnBroj_i ndeksa = New System.Data.Dat aColumn("Broj
indeksa", GetType(String) , Nothing, System.Data.Map pingType.Elemen t)
Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_Colu mnPropNameInRow ",
"Broj_indek sa")
Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_Colu mnPropNameInTab le",
"Broj_indeksaCo lumn")
Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_Colu mnVarNameInTabl e",
"columnBroj_ind eksa")
Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_User ColumnName",
"Broj indeksa")
MyBase.Columns. Add(Me.columnBr oj_indeksa)
Me.columnBroj_p ohadjanja = New System.Data.Dat aColumn("Broj
pohadjanja", GetType(Integer ), Nothing, System.Data.Map pingType.Elemen t)
Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_C olumnPropNameIn Row",
"Broj_pohadjanj a")
Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_C olumnPropNameIn Table",
"Broj_pohadjanj aColumn")
Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_C olumnVarNameInT able",
"columnBroj_poh adjanja")
Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_U serColumnName",
"Broj pohadjanja")
MyBase.Columns. Add(Me.columnBr oj_pohadjanja)
Me.Constraints. Add(New
System.Data.Uni queConstraint(" Constraint1", New System.Data.Dat aColumn()
{Me.columnBroj_ iksice}, true))
Me.columnBroj_i ksice.AllowDBNu ll = false
Me.columnBroj_i ksice.Unique = true
Me.columnPrezim e.MaxLength = 255
Me.columnIme.Ma xLength = 255
Me.columnBroj_i ndeksa.MaxLengt h = 255
End Sub

I get this error (in the post before) when I add new column with this code:

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Dim noviStupac As Data.DataColumn = New Data.DataColumn ("Test
Marko", System.Type.Get Type("System.In t32"), Nothing,
System.Data.Map pingType.Elemen t)
noviStupac.Auto Increment = False
noviStupac.Defa ultValue = 0

Try
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Add(noviStup ac)
'Dodaje stupac u tablicu

Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Accep tChanges()

Form2.Table1Dat aGridView.AutoG enerateColumns = True 'Kada dodas
stupac da se prikaze u prozoru

Novo(Form2.Stud enti1Data.Table s.Item(Index(Co mboBox1.Text)). TableName,
"Fill") 'Ponovo prikazuje tablicu u datom prozoru

Catch ex As Exception

MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exc lamation,
"Upozorenje !")

End Try
End Sub

I didn't set autoincrement as true.
I dont know wat is wrong!
Can you help me...!
Jan 23 '07 #5
Well, I can tell you the first thing I would do is rename the
data columns to *NOT* have spaces in the names. That's just a
recipe for disaster.

You said previously it was stopping when trying to update the
record, and I asked if there was a primary key, which Cor also
asked when you reposted this in a new thread and you never answered.

Second, what exactly is your problem, and where is it stopping?

Robin S.
-------------------------------
"explode" <ur**@mzos.hrwr ote in message
news:ep******** **@news1.carnet .hr...
My table has 5 columns: Broj iksice, Prezime, Ime, Broj indeksa, Broj
pohadjanja.
This is the code in the dataset designer VB made it by it self:

Private Sub InitClass()
Me.columnBroj_i ksice = New System.Data.Dat aColumn("Broj
iksice", GetType(Double) , Nothing, System.Data.Map pingType.Elemen t)

Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_Colum nPropNameInRow" ,
"Broj_iksic e")

Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_Colum nPropNameInTabl e",
"Broj_iksiceCol umn")

Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_Colum nVarNameInTable ",
"columnBroj_iks ice")

Me.columnBroj_i ksice.ExtendedP roperties.Add(" Generator_UserC olumnName",
"Broj iksice")
MyBase.Columns. Add(Me.columnBr oj_iksice)
Me.columnPrezim e = New System.Data.Dat aColumn("Prezim e",
GetType(String) , Nothing, System.Data.Map pingType.Elemen t)
MyBase.Columns. Add(Me.columnPr ezime)
Me.columnIme = New System.Data.Dat aColumn("Ime",
GetType(String) , Nothing, System.Data.Map pingType.Elemen t)
MyBase.Columns. Add(Me.columnIm e)
Me.columnBroj_i ndeksa = New System.Data.Dat aColumn("Broj
indeksa", GetType(String) , Nothing, System.Data.Map pingType.Elemen t)

Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_Colu mnPropNameInRow ",
"Broj_indek sa")

Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_Colu mnPropNameInTab le",
"Broj_indeksaCo lumn")

Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_Colu mnVarNameInTabl e",
"columnBroj_ind eksa")

Me.columnBroj_i ndeksa.Extended Properties.Add( "Generator_User ColumnName",
"Broj indeksa")
MyBase.Columns. Add(Me.columnBr oj_indeksa)
Me.columnBroj_p ohadjanja = New System.Data.Dat aColumn("Broj
pohadjanja", GetType(Integer ), Nothing,
System.Data.Map pingType.Elemen t)

Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_C olumnPropNameIn Row",
"Broj_pohadjanj a")

Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_C olumnPropNameIn Table",
"Broj_pohadjanj aColumn")

Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_C olumnVarNameInT able",
"columnBroj_poh adjanja")

Me.columnBroj_p ohadjanja.Exten dedProperties.A dd("Generator_U serColumnName",
"Broj pohadjanja")
MyBase.Columns. Add(Me.columnBr oj_pohadjanja)
Me.Constraints. Add(New
System.Data.Uni queConstraint(" Constraint1", New
System.Data.Dat aColumn() {Me.columnBroj_ iksice}, true))
Me.columnBroj_i ksice.AllowDBNu ll = false
Me.columnBroj_i ksice.Unique = true
Me.columnPrezim e.MaxLength = 255
Me.columnIme.Ma xLength = 255
Me.columnBroj_i ndeksa.MaxLengt h = 255
End Sub

I get this error (in the post before) when I add new column with this
code:

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button4.Click
Dim noviStupac As Data.DataColumn = New Data.DataColumn ("Test
Marko", System.Type.Get Type("System.In t32"), Nothing,
System.Data.Map pingType.Elemen t)
noviStupac.Auto Increment = False
noviStupac.Defa ultValue = 0

Try

Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Colum ns.Add(noviStup ac)
'Dodaje stupac u tablicu
Form2.Studenti1 Data.Tables.Ite m(Index(ComboBo x1.Text)).Accep tChanges()

Form2.Table1Dat aGridView.AutoG enerateColumns = True 'Kada
dodas stupac da se prikaze u prozoru
Novo(Form2.Stud enti1Data.Table s.Item(Index(Co mboBox1.Text)). TableName,
"Fill") 'Ponovo prikazuje tablicu u datom prozoru

Catch ex As Exception

MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exc lamation,
"Upozorenje !")

End Try
End Sub

I didn't set autoincrement as true.
I dont know wat is wrong!
Can you help me...!

Jan 25 '07 #6

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

Similar topics

0
2880
by: Arno Huetter | last post by:
Hi there, I try to execute a DB-Update using ADO.NET CommandBuilder (MSORA Data Provider) on Oracle 8.1.6 (unfortunately, ODP.NET seems to require Oracle 9i or above). One of ADO.NET's DataTable columns is of type Byte-Array, and refers to a RAW column on the Oracle-DB. The CommandBuilder generates Update-Statements of this kind:
4
5302
by: Rustam Bogubaev | last post by:
Hi, I have a table with the following columns: ID INTEGEDR, Name VARCHAR(32), Surname VARCHAR(32), GroupID INTEGER, SubGroupOneID INTEGER, SubGroupTwoID INTEGER
9
4170
by: allenj | last post by:
DB2 UDB 7.2 WSE Fixpak 9 Linux Red Hat 7.3 I have some library code (written in Java, if that matters) that processes maintenance screens that are presented to the end-users as forms in a browser. Because the code is generic, working against any table, I am dynamically generating UPDATE statements that update
0
1238
by: Raposa Velha | last post by:
Posting a solution to a problem I had. In the the following code I was getting an error something like "80004005 too many columns selected" After long time searching the a2k help and this NW, I found the error. The query string I was using to build the RS hadn't all the table fields! When I select all the fields, even if I don't want to all...
68
6770
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
5361
by: binder | last post by:
I have a stored procedure that inserts values into five columns of a table. I need another stored procedure that will allow the user to pass one or more of those parameters and update only the column for the data that was passed. In other words, the update may only have one or two of the parameters that was originally provided in the insert....
2
24754
by: BF | last post by:
Hi, I have some tables where I import data in, lots of field have gotten a NULL value which the application can not handle. Now can I replace each NULL value with '' in a columns with: update <tableset = '' where IS NULL But because there are lots of columns this is pretty much work, also there are multiple tables.
2
3364
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList(); private SQLiteConnection cn; private SQLiteDataAdapter adapterMacros; cn = new SQLiteConnection("Data Source = irDatabase.db3"); SQLiteCommand...
7
2407
by: Norman Scheffler | last post by:
Hello, I wrote an update trigger to detect the names of the updated columns of a table using the UPDATED(columnName) function. In a stored procedure I wrote code to update user information with given parameters. Update daUser SET strFirstName = @vstrFirstName, strLastName = @vstrLastName,
0
7629
marktang
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...
0
7549
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7835
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. ...
0
6183
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...
1
5455
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...
0
5172
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...
0
3602
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...
1
2045
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 we have to send another system
0
869
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...

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.