By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,874 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,874 IT Pros & Developers. It's quick & easy.

New columns and update problem...!

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.