473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

New columns and update problem...!

I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As
String) that creates a new oledbDataAdapter 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Try
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Add("TEST
Marko", GetType(Integer))
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).AcceptChanges()
Form2.Table1DataGridView.AutoGenerateColumns = True
Novo(Form2.Studenti1Data.Tables.Item(Index(ComboBo x1.Text)).TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exclamation, "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.OleDb.OleDbException was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microsoft JET Database Engine"
StackTrace:
at
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at
System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable
dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 305
at Diplomski1.Form2.Table1BindingNavigatorSaveItem_Cl ick(Object
sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2.v b:line 8
at System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key,
EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(Event Args e)
at System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(M ouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventIntera ctive(EventArgs
e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(Event Args e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Procedur for the oledbDataAdapter is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySetti ngs.Default.Studenti1Connection)
Dim SelectCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim UpdateCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim InsertCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim DeleteCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
tableMapping.ColumnMappings.Add(Form2.Studenti1Dat a.Tables.Item(Index(ComboBox1.Text)).Columns.Item( i).ColumnName,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i
nova.TableMappings.Add(tableMapping)
nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True
SelectCom.Connection = veza
SelectCom.CommandType = CommandType.Text
SelectCom.CommandText = "SELECT * FROM " & nova1
UpdateCom.Connection = veza
UpdateCom.CommandType = CommandType.Text
UpdateCom.CommandText = "UPDATE " & nova1 & " SET " & InsSql(ComboBox1.Text,
"Treci") & " WHERE [Broj iksice]=?" '[Broj iksice]=?, [Prezime]=?, [Ime]=?,
[Broj indeksa]=?, [Broj pohadjanja]=? & _
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Current, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Current, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion.Current, False,
Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
UpdateCom.Parameters.Add(New
OleDb.OleDbParameter(Form2.Studenti1Data.Tables.It em(Index(ComboBox1.Text)).Columns.Item(i).ColumnNa me,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
DataRowVersion.Current, False, Nothing))
Next i
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Original, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion.Original, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion.Original, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Original, True,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion.Original, True,
Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari " &
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
DataRowVersion.Original, True, Nothing))
Next i
InsertCom.Connection = veza
InsertCom.CommandType = CommandType.Text
InsertCom.CommandText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime], [Ime],
[Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Parameters.Add("Broj iksice", OleDb.OleDbType.Double, 0, "Broj
iksice")
InsertCom.Parameters.Add("Prezime", OleDb.OleDbType.WChar, 0, "Prezime")
InsertCom.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0, "Ime")
InsertCom.Parameters.Add("Broj indeksa", OleDb.OleDbType.WChar, 0, "Broj
indeksa")
InsertCom.Parameters.Add("Broj pohadjanja", OleDb.OleDbType.Integer, 0,
"Broj pohadjanja")
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
InsertCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(Index(ComboBox1.Text)).Columns.Item(i).Colu mnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i
DeleteCom.Connection = veza
DeleteCom.CommandType = CommandType.Text
DeleteCom.CommandText = "DELETE * FROM " & nova1 & " WHERE [Broj iksice]=?"
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, False,
CType(20, Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion.Original,
Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
DeleteCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(Index(ComboBox1.Text)).Columns.Item(i).Colu mnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i

nova.SelectCommand = SelectCom
nova.UpdateCommand = UpdateCom
nova.DeleteCommand = DeleteCom
nova.InsertCommand = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2.Studenti1Data.Tables.Item(Index(Co mboBox1.Text)))
End If
If nova2 = "Update" Then
nova.Update(Form2.Studenti1Data.Tables.Item(Index( ComboBox1.Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox1.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.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Count -
1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Item(i).ColumnName &
"]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.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.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Count -
1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.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 2130
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.hrschreef 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 oledbDataAdapter 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Try
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Add("TEST
Marko", GetType(Integer))
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).AcceptChanges()
Form2.Table1DataGridView.AutoGenerateColumns = True
Novo(Form2.Studenti1Data.Tables.Item(Index(ComboBo x1.Text)).TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exclamation, "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.OleDb.OleDbException was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microsoft JET Database Engine"
StackTrace:
at
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at
System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable
dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 305
at Diplomski1.Form2.Table1BindingNavigatorSaveItem_Cl ick(Object
sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2.v b:line 8
at System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key,
EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(Event Args e)
at System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(M ouseEventArgs
e)
at System.Windows.Forms.ToolStripItem.FireEventIntera ctive(EventArgs
e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(Event Args e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Procedur for the oledbDataAdapter is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySetti ngs.Default.Studenti1Connection)
Dim SelectCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim UpdateCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim InsertCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim DeleteCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
tableMapping.ColumnMappings.Add(Form2.Studenti1Dat a.Tables.Item(Index(ComboBox1.Text)).Columns.Item( i).ColumnName,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i
nova.TableMappings.Add(tableMapping)
nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True
SelectCom.Connection = veza
SelectCom.CommandType = CommandType.Text
SelectCom.CommandText = "SELECT * FROM " & nova1
UpdateCom.Connection = veza
UpdateCom.CommandType = CommandType.Text
UpdateCom.CommandText = "UPDATE " & nova1 & " SET " &
InsSql(ComboBox1.Text, "Treci") & " WHERE [Broj iksice]=?" '[Broj
iksice]=?, [Prezime]=?, [Ime]=?, [Broj indeksa]=?, [Broj pohadjanja]=? & _
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Current, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Current, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion.Current, False,
Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
UpdateCom.Parameters.Add(New
OleDb.OleDbParameter(Form2.Studenti1Data.Tables.It em(Index(ComboBox1.Text)).Columns.Item(i).ColumnNa me,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
DataRowVersion.Current, False, Nothing))
Next i
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, CType(20,
Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Original, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Prezime", DataRowVersion.Original, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Ime", DataRowVersion.Original, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Original, True,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte), "Broj pohadjanja", DataRowVersion.Original, True,
Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari " &
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, CType(0,
Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
DataRowVersion.Original, True, Nothing))
Next i
InsertCom.Connection = veza
InsertCom.CommandType = CommandType.Text
InsertCom.CommandText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime], [Ime],
[Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Parameters.Add("Broj iksice", OleDb.OleDbType.Double, 0, "Broj
iksice")
InsertCom.Parameters.Add("Prezime", OleDb.OleDbType.WChar, 0, "Prezime")
InsertCom.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0, "Ime")
InsertCom.Parameters.Add("Broj indeksa", OleDb.OleDbType.WChar, 0, "Broj
indeksa")
InsertCom.Parameters.Add("Broj pohadjanja", OleDb.OleDbType.Integer, 0,
"Broj pohadjanja")
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
InsertCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(Index(ComboBox1.Text)).Columns.Item(i).Colu mnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i
DeleteCom.Connection = veza
DeleteCom.CommandType = CommandType.Text
DeleteCom.CommandText = "DELETE * FROM " & nova1 & " WHERE [Broj
iksice]=?"
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input, False,
CType(20, Byte), CType(0, Byte), "Broj iksice", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion.Original, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count - 1
DeleteCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(Index(ComboBox1.Text)).Columns.Item(i).Colu mnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i

nova.SelectCommand = SelectCom
nova.UpdateCommand = UpdateCom
nova.DeleteCommand = DeleteCom
nova.InsertCommand = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2.Studenti1Data.Tables.Item(Index(Co mboBox1.Text)))
End If
If nova2 = "Update" Then
nova.Update(Form2.Studenti1Data.Tables.Item(Index( ComboBox1.Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox1.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.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Count - 1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Item(i).ColumnName
& "]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.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.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Count - 1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.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.hrwrote 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 oledbDataAdapter 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Try
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Add("TEST
Marko", GetType(Integer))
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).AcceptChanges()
Form2.Table1DataGridView.AutoGenerateColumns = True
Novo(Form2.Studenti1Data.Tables.Item(Index(ComboBo x1.Text)).TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exclamation,
"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.OleDb.OleDbException was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microsoft JET Database Engine"
StackTrace:
at
System.Data.Common.DbDataAdapter.UpdatedRowStatusE rrors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at
System.Data.Common.DbDataAdapter.UpdatedRowStatus( RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at
System.Data.Common.DbDataAdapter.UpdateFromDataTab le(DataTable
dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1.v b:line 305
at Diplomski1.Form2.Table1BindingNavigatorSaveItem_Cl ick(Object
sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2.v b:line 8
at System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key,
EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(Event Args e)
at System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
at
System.Windows.Forms.ToolStripItem.HandleMouseUp(M ouseEventArgs e)
at
System.Windows.Forms.ToolStripItem.FireEventIntera ctive(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(Event Args e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Create Instance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Procedur for the oledbDataAdapter is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySetti ngs.Default.Studenti1Connection)
Dim SelectCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim UpdateCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim InsertCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim DeleteCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count -
1
tableMapping.ColumnMappings.Add(Form2.Studenti1Dat a.Tables.Item(Index(ComboBox1.Text)).Columns.Item( i).ColumnName,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i
nova.TableMappings.Add(tableMapping)
nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True
SelectCom.Connection = veza
SelectCom.CommandType = CommandType.Text
SelectCom.CommandText = "SELECT * FROM " & nova1
UpdateCom.Connection = veza
UpdateCom.CommandType = CommandType.Text
UpdateCom.CommandText = "UPDATE " & nova1 & " SET " &
InsSql(ComboBox1.Text, "Treci") & " WHERE [Broj iksice]=?" '[Broj
iksice]=?, [Prezime]=?, [Ime]=?, [Broj indeksa]=?, [Broj pohadjanja]=?
& _
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input,
CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Current,
False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Current, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion.Current, False, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count -
1
UpdateCom.Parameters.Add(New
OleDb.OleDbParameter(Form2.Studenti1Data.Tables.It em(Index(ComboBox1.Text)).Columns.Item(i).ColumnNa me,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
DataRowVersion.Current, False, Nothing))
Next i
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input,
CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion.Original, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Original,
False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Original, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
indeksa", OleDb.OleDbType.WChar, 0,
System.Data.ParameterDirection.Input, CType(0, Byte), CType(0, Byte),
"Broj indeksa", DataRowVersion.Original, True, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
pohadjanja", OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, CType(0, Byte), CType(0, Byte),
"Broj pohadjanja", DataRowVersion.Original, True, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count -
1
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari " &
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName,
DataRowVersion.Original, True, Nothing))
Next i
InsertCom.Connection = veza
InsertCom.CommandType = CommandType.Text
InsertCom.CommandText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime],
[Ime], [Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Parameters.Add("Broj iksice", OleDb.OleDbType.Double, 0,
"Broj iksice")
InsertCom.Parameters.Add("Prezime", OleDb.OleDbType.WChar, 0,
"Prezime")
InsertCom.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0, "Ime")
InsertCom.Parameters.Add("Broj indeksa", OleDb.OleDbType.WChar, 0,
"Broj indeksa")
InsertCom.Parameters.Add("Broj pohadjanja", OleDb.OleDbType.Integer,
0, "Broj pohadjanja")
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count -
1
InsertCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(Index(ComboBox1.Text)).Columns.Item(i).Colu mnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i
DeleteCom.Connection = veza
DeleteCom.CommandType = CommandType.Text
DeleteCom.CommandText = "DELETE * FROM " & nova1 & " WHERE [Broj
iksice]=?"
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input,
False, CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, False,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Original,
Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
True, CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion.Original, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Count -
1
DeleteCom.Parameters.Add(Form2.Studenti1Data.Table s.Item(Index(ComboBox1.Text)).Columns.Item(i).Colu mnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Item(i).ColumnName)
Next i

nova.SelectCommand = SelectCom
nova.UpdateCommand = UpdateCom
nova.DeleteCommand = DeleteCom
nova.InsertCommand = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2.Studenti1Data.Tables.Item(Index(Co mboBox1.Text)))
End If
If nova2 = "Update" Then
nova.Update(Form2.Studenti1Data.Tables.Item(Index( ComboBox1.Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox1.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.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Count - 1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Item(i).ColumnName
& "]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.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.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.Count - 1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Col umns.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**************@TK2MSFTNGP05.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.hrschreef 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 oledbDataAdapter 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Try
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Add("TEST
Marko", GetType(Integer))
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).AcceptChanges()
Form2.Table1DataGridView.AutoGenerateColumns = True
Novo(Form2.Studenti1Data.Tables.Item(Index(ComboB ox1.Text)).TableName,
"Fill")

Catch ex As Exception
MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exclamation,
"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.OleDb.OleDbException was unhandled
ErrorCode=-2147217887
Message="Cannot update 'TEST Marko'; field not updateable."
Source="Microsoft JET Database Engine"
StackTrace:
at
System.Data.Common.DbDataAdapter.UpdatedRowStatus Errors(RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32
commandCount)
at
System.Data.Common.DbDataAdapter.UpdatedRowStatus (RowUpdatedEventArgs
rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32
commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at
System.Data.Common.DbDataAdapter.UpdateFromDataTa ble(DataTable
dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at Diplomski1.Form1.Novo(String nova1, String nova2) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form1. vb:line 305
at Diplomski1.Form2.Table1BindingNavigatorSaveItem_Cl ick(Object
sender, EventArgs e) in
D:\OdMomka\Diplomski\Diplomski1\Diplomski1\Form2. vb:line 8
at System.Windows.Forms.ToolStripItem.RaiseEvent(Obje ct key,
EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(Event Args e)
at System.Windows.Forms.ToolStripItem.HandleClick(Eve ntArgs e)
at
System.Windows.Forms.ToolStripItem.HandleMouseUp( MouseEventArgs e)
at
System.Windows.Forms.ToolStripItem.FireEventInter active(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(Event Args e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEven tArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow. OnMessage(Message&
m)
at
System.Windows.Forms.Control.ControlNativeWindow. WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.Dispatch MessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager .System.Windows.Forms.UnsafeNativeMethods.IMsoComp onentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Ru nMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Ru nMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext
context)
at
Microsoft.VisualBasic.ApplicationServices.Windows FormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.Windows FormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.Windows FormsApplicationBase.Run(String[]
commandLine)
at Diplomski1.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAss embly()
at
System.Runtime.Hosting.ApplicationActivator.Creat eInstance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.Creat eInstance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Ru nUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Procedur for the oledbDataAdapter is:
Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String)
Dim i As Integer
Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim veza As OleDb.OleDbConnection = New
OleDb.OleDbConnection(Global.Diplomski1.My.MySett ings.Default.Studenti1Connection)
Dim SelectCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim UpdateCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim InsertCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim DeleteCom As OleDb.OleDbCommand = New OleDb.OleDbCommand
Dim tableMapping As System.Data.Common.DataTableMapping = New
System.Data.Common.DataTableMapping("Marko", ComboBox1.Text)
veza.Open()
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Count
- 1
tableMapping.ColumnMappings.Add(Form2.Studenti1Da ta.Tables.Item(Index(ComboBox1.Text)).Columns.Item (i).ColumnName,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Item(i).ColumnName)
Next i
nova.TableMappings.Add(tableMapping)
nova.MissingMappingAction = MissingMappingAction.Passthrough
nova.MissingSchemaAction = MissingSchemaAction.AddWithKey
nova.AcceptChangesDuringUpdate = True
SelectCom.Connection = veza
SelectCom.CommandType = CommandType.Text
SelectCom.CommandText = "SELECT * FROM " & nova1
UpdateCom.Connection = veza
UpdateCom.CommandType = CommandType.Text
UpdateCom.CommandText = "UPDATE " & nova1 & " SET " &
InsSql(ComboBox1.Text, "Treci") & " WHERE [Broj iksice]=?" '[Broj
iksice]=?, [Prezime]=?, [Ime]=?, [Broj indeksa]=?, [Broj
pohadjanja]=? & _
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input,
CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Current,
False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Current, False,
Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion.Current, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion.Current, False, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Count
- 1
UpdateCom.Parameters.Add(New
OleDb.OleDbParameter(Form2.Studenti1Data.Tables.I tem(Index(ComboBox1.Text)).Columns.Item(i).ColumnN ame,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Item(i).ColumnName,
DataRowVersion.Current, False, Nothing))
Next i
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
iksice", OleDb.OleDbType.Double, 0,
System.Data.ParameterDirection.Input, CType(20, Byte), CType(0,
Byte), "Broj iksice", DataRowVersion.Original, False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Prezime", DataRowVersion.Original,
False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte), "Ime", DataRowVersion.Original,
False, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
indeksa", OleDb.OleDbType.WChar, 0,
System.Data.ParameterDirection.Input, CType(0, Byte), CType(0, Byte),
"Broj indeksa", DataRowVersion.Original, True, Nothing))
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari Broj
pohadjanja", OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, CType(0, Byte), CType(0, Byte),
"Broj pohadjanja", DataRowVersion.Original, True, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Count
- 1
UpdateCom.Parameters.Add(New OleDb.OleDbParameter("stari " &
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Item(i).ColumnName,
_
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
CType(0, Byte), CType(0, Byte),
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Item(i).ColumnName,
DataRowVersion.Original, True, Nothing))
Next i
InsertCom.Connection = veza
InsertCom.CommandType = CommandType.Text
InsertCom.CommandText = "INSERT INTO " & nova1 & " (" &
InsSql(ComboBox1.Text, "Prvi") & ")" & " VALUES " & "(" &
InsSql(ComboBox1.Text, "Drugi") & ")" '" ([Broj iksice], [Prezime],
[Ime], [Broj indeksa], " & _
'"[Broj pohadjanja]) VALUES (?,?,?,?,?)"
InsertCom.Parameters.Add("Broj iksice", OleDb.OleDbType.Double, 0,
"Broj iksice")
InsertCom.Parameters.Add("Prezime", OleDb.OleDbType.WChar, 0,
"Prezime")
InsertCom.Parameters.Add("Ime", OleDb.OleDbType.WChar, 0, "Ime")
InsertCom.Parameters.Add("Broj indeksa", OleDb.OleDbType.WChar, 0,
"Broj indeksa")
InsertCom.Parameters.Add("Broj pohadjanja", OleDb.OleDbType.Integer,
0, "Broj pohadjanja")
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Count
- 1
InsertCom.Parameters.Add(Form2.Studenti1Data.Tabl es.Item(Index(ComboBox1.Text)).Columns.Item(i).Col umnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Item(i).ColumnName)
Next i
DeleteCom.Connection = veza
DeleteCom.CommandType = CommandType.Text
DeleteCom.CommandText = "DELETE * FROM " & nova1 & " WHERE [Broj
iksice]=?"
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj iksice",
OleDb.OleDbType.Double, 0, System.Data.ParameterDirection.Input,
False, CType(20, Byte), CType(0, Byte), "Broj iksice",
DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Prezime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "Prezime",
DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Ime",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input,
False, CType(0, Byte), CType(0, Byte), "Ime",
DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj indeksa",
OleDb.OleDbType.WChar, 0, System.Data.ParameterDirection.Input, True,
CType(0, Byte), CType(0, Byte), "Broj indeksa",
DataRowVersion.Original, Nothing))
DeleteCom.Parameters.Add(New OleDb.OleDbParameter("Broj pohadjanja",
OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input,
True, CType(0, Byte), CType(0, Byte), "Broj pohadjanja",
DataRowVersion.Original, Nothing))
For i = 5 To
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Count
- 1
DeleteCom.Parameters.Add(Form2.Studenti1Data.Tabl es.Item(Index(ComboBox1.Text)).Columns.Item(i).Col umnName,
_
OleDb.OleDbType.Integer, 0,
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.T ext)).Columns.Item(i).ColumnName)
Next i

nova.SelectCommand = SelectCom
nova.UpdateCommand = UpdateCom
nova.DeleteCommand = DeleteCom
nova.InsertCommand = InsertCom
If nova2 = "Fill" Then
nova.Fill(Form2.Studenti1Data.Tables.Item(Index(C omboBox1.Text)))
End If
If nova2 = "Update" Then
nova.Update(Form2.Studenti1Data.Tables.Item(Index (ComboBox1.Text)))
End If
veza.Close()
End Sub
InsSql(ComboBox1.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.Studenti1Data.Tables.Item(Index(imeTab)).Co lumns.Count - 1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Co lumns.Item(i).ColumnName
& "]"
Next i
End If
If tipSql = "Drugi" Then
sql = "?"
For i = 0 To
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Co lumns.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.Studenti1Data.Tables.Item(Index(imeTab)).Co lumns.Count - 1
sql = sql & ", [" &
Form2.Studenti1Data.Tables.Item(Index(imeTab)).Co lumns.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_iksice = New System.Data.DataColumn("Broj iksice",
GetType(Double), Nothing, System.Data.MappingType.Element)
Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_ColumnPropNameInRow",
"Broj_iksice")
Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_ColumnPropNameInTable",
"Broj_iksiceColumn")
Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_ColumnVarNameInTable",
"columnBroj_iksice")
Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_UserColumnName",
"Broj iksice")
MyBase.Columns.Add(Me.columnBroj_iksice)
Me.columnPrezime = New System.Data.DataColumn("Prezime",
GetType(String), Nothing, System.Data.MappingType.Element)
MyBase.Columns.Add(Me.columnPrezime)
Me.columnIme = New System.Data.DataColumn("Ime",
GetType(String), Nothing, System.Data.MappingType.Element)
MyBase.Columns.Add(Me.columnIme)
Me.columnBroj_indeksa = New System.Data.DataColumn("Broj
indeksa", GetType(String), Nothing, System.Data.MappingType.Element)
Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_ColumnPropNameInRow",
"Broj_indeksa")
Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_ColumnPropNameInTable",
"Broj_indeksaColumn")
Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_ColumnVarNameInTable",
"columnBroj_indeksa")
Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_UserColumnName",
"Broj indeksa")
MyBase.Columns.Add(Me.columnBroj_indeksa)
Me.columnBroj_pohadjanja = New System.Data.DataColumn("Broj
pohadjanja", GetType(Integer), Nothing, System.Data.MappingType.Element)
Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_ColumnPropNameInRow",
"Broj_pohadjanja")
Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_ColumnPropNameInTable",
"Broj_pohadjanjaColumn")
Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_ColumnVarNameInTable",
"columnBroj_pohadjanja")
Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_UserColumnName",
"Broj pohadjanja")
MyBase.Columns.Add(Me.columnBroj_pohadjanja)
Me.Constraints.Add(New
System.Data.UniqueConstraint("Constraint1", New System.Data.DataColumn()
{Me.columnBroj_iksice}, true))
Me.columnBroj_iksice.AllowDBNull = false
Me.columnBroj_iksice.Unique = true
Me.columnPrezime.MaxLength = 255
Me.columnIme.MaxLength = 255
Me.columnBroj_indeksa.MaxLength = 255
End Sub

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

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim noviStupac As Data.DataColumn = New Data.DataColumn("Test
Marko", System.Type.GetType("System.Int32"), Nothing,
System.Data.MappingType.Element)
noviStupac.AutoIncrement = False
noviStupac.DefaultValue = 0

Try
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Add(noviStupac)
'Dodaje stupac u tablicu

Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).AcceptChanges()

Form2.Table1DataGridView.AutoGenerateColumns = True 'Kada dodas
stupac da se prikaze u prozoru

Novo(Form2.Studenti1Data.Tables.Item(Index(ComboBo x1.Text)).TableName,
"Fill") 'Ponovo prikazuje tablicu u datom prozoru

Catch ex As Exception

MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exclamation,
"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.hrwrote 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_iksice = New System.Data.DataColumn("Broj
iksice", GetType(Double), Nothing, System.Data.MappingType.Element)

Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_ColumnPropNameInRow",
"Broj_iksice")

Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_ColumnPropNameInTable",
"Broj_iksiceColumn")

Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_ColumnVarNameInTable",
"columnBroj_iksice")

Me.columnBroj_iksice.ExtendedProperties.Add("Gener ator_UserColumnName",
"Broj iksice")
MyBase.Columns.Add(Me.columnBroj_iksice)
Me.columnPrezime = New System.Data.DataColumn("Prezime",
GetType(String), Nothing, System.Data.MappingType.Element)
MyBase.Columns.Add(Me.columnPrezime)
Me.columnIme = New System.Data.DataColumn("Ime",
GetType(String), Nothing, System.Data.MappingType.Element)
MyBase.Columns.Add(Me.columnIme)
Me.columnBroj_indeksa = New System.Data.DataColumn("Broj
indeksa", GetType(String), Nothing, System.Data.MappingType.Element)

Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_ColumnPropNameInRow",
"Broj_indeksa")

Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_ColumnPropNameInTable",
"Broj_indeksaColumn")

Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_ColumnVarNameInTable",
"columnBroj_indeksa")

Me.columnBroj_indeksa.ExtendedProperties.Add("Gene rator_UserColumnName",
"Broj indeksa")
MyBase.Columns.Add(Me.columnBroj_indeksa)
Me.columnBroj_pohadjanja = New System.Data.DataColumn("Broj
pohadjanja", GetType(Integer), Nothing,
System.Data.MappingType.Element)

Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_ColumnPropNameInRow",
"Broj_pohadjanja")

Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_ColumnPropNameInTable",
"Broj_pohadjanjaColumn")

Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_ColumnVarNameInTable",
"columnBroj_pohadjanja")

Me.columnBroj_pohadjanja.ExtendedProperties.Add("G enerator_UserColumnName",
"Broj pohadjanja")
MyBase.Columns.Add(Me.columnBroj_pohadjanja)
Me.Constraints.Add(New
System.Data.UniqueConstraint("Constraint1", New
System.Data.DataColumn() {Me.columnBroj_iksice}, true))
Me.columnBroj_iksice.AllowDBNull = false
Me.columnBroj_iksice.Unique = true
Me.columnPrezime.MaxLength = 255
Me.columnIme.MaxLength = 255
Me.columnBroj_indeksa.MaxLength = 255
End Sub

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

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim noviStupac As Data.DataColumn = New Data.DataColumn("Test
Marko", System.Type.GetType("System.Int32"), Nothing,
System.Data.MappingType.Element)
noviStupac.AutoIncrement = False
noviStupac.DefaultValue = 0

Try

Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).Columns.Add(noviStupac)
'Dodaje stupac u tablicu
Form2.Studenti1Data.Tables.Item(Index(ComboBox1.Te xt)).AcceptChanges()

Form2.Table1DataGridView.AutoGenerateColumns = True 'Kada
dodas stupac da se prikaze u prozoru
Novo(Form2.Studenti1Data.Tables.Item(Index(ComboBo x1.Text)).TableName,
"Fill") 'Ponovo prikazuje tablicu u datom prozoru

Catch ex As Exception

MsgBox("Vec postoji dati stupac!", MsgBoxStyle.Exclamation,
"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
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...
4
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...
9
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...
0
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...
68
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
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...
2
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...
2
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();...
7
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.