ismilovic Ivan Smilović Istra
Član broj: 63197 Poruke: 89 *.net.t-com.hr.
|
Zahvaljujem na odgovorima
Csharp
Rows[0] postoji
majstor_01
Art nije primarni knjuč - barem ga nisam definirao
dusans - posebno hvala na obješnjenju
Nisam baš upio primjetit grešku zato prilažem source code.
Još jedna napomena:
Kada dodam
cRow.BeginEdit();
...
cRow.EndEdit();
dataTable1.AcceptChanges();
Greška se ne javlja ali izostaje upis u datoteku
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Smilovic;
namespace Update
{
/// <summary>
/// Summary description for WinForm1.
/// </summary>
public class WinForm1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button Upis;
public DataRow cRow;
private System.Windows.Forms.DataGrid dataGrid1;
private Borland.Data.Provider.BdpConnection IbConn;
private Borland.Data.Provider.BdpCommand bdpSelectCommand1;
private Borland.Data.Provider.BdpCommand bdpInsertCommand1;
private Borland.Data.Provider.BdpCommand bdpUpdateCommand1;
private Borland.Data.Provider.BdpCommand bdpDeleteCommand1;
private Borland.Data.Provider.BdpDataAdapter da;
private System.Data.DataSet ds;
private System.Data.DataTable dataTable1;
private System.Data.DataColumn dataColumn1;
private System.Data.DataColumn dataColumn2;
public WinForm1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Upis = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.IbConn = new Borland.Data.Provider.BdpConnection();
this.da = new Borland.Data.Provider.BdpDataAdapter();
this.ds = new System.Data.DataSet();
this.dataTable1 = new System.Data.DataTable();
this.dataColumn1 = new System.Data.DataColumn();
this.dataColumn2 = new System.Data.DataColumn();
this.bdpDeleteCommand1 = new Borland.Data.Provider.BdpCommand();
this.bdpInsertCommand1 = new Borland.Data.Provider.BdpCommand();
this.bdpSelectCommand1 = new Borland.Data.Provider.BdpCommand();
this.bdpUpdateCommand1 = new Borland.Data.Provider.BdpCommand();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.da)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ds)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();
this.SuspendLayout();
//
// Upis
//
this.Upis.Location = new System.Drawing.Point(104, 288);
this.Upis.Name = "Upis";
this.Upis.TabIndex = 3;
this.Upis.Text = "Upis";
this.Upis.Click += new System.EventHandler(this.Upis_Click);
//
// dataGrid1
//
this.dataGrid1.CaptionFont = new System.Drawing.Font("Times New Roman", 10.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataTable1;
this.dataGrid1.FlatMode = true;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 0);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(208, 265);
this.dataGrid1.TabIndex = 2;
//
// IbConn
//
this.IbConn.ConnectionOptions = "waitonlocks=False;commitretain=False;sqldialect=3;transaction isol" +
"ation=ReadCommitted;servercharset=;rolename=myrole";
this.IbConn.ConnectionString = "database=D:\\C#\\Data\\MIX.GDB;assembly=Borland.Data.Interbase, Versi" +
"on=2.0.0.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b;vend" +
"orclient=gds32.dll;provider=Interbase;username=sysdba;password=ma" +
"sterkey";
//
// da
//
this.da.Active = true;
this.da.DataSet = this.ds;
this.da.DataTable = this.dataTable1;
this.da.DeleteCommand = this.bdpDeleteCommand1;
this.da.InsertCommand = this.bdpInsertCommand1;
this.da.SelectCommand = this.bdpSelectCommand1;
this.da.StartRecord = 0;
this.da.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "ARTIKLI", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ART", "ART"),
new System.Data.Common.DataColumnMapping("NAZIV", "NAZIV")})});
this.da.UpdateCommand = this.bdpUpdateCommand1;
//
// ds
//
this.ds.DataSetName = "NewDataSet";
this.ds.Locale = new System.Globalization.CultureInfo("hr-HR");
this.ds.Tables.AddRange(new System.Data.DataTable[] {
this.dataTable1});
//
// dataTable1
//
this.dataTable1.Columns.AddRange(new System.Data.DataColumn[] {
this.dataColumn1,
this.dataColumn2});
this.dataTable1.TableName = "ARTIKLI";
//
// dataColumn1
//
this.dataColumn1.ColumnName = "ART";
this.dataColumn1.MaxLength = 6;
//
// dataColumn2
//
this.dataColumn2.ColumnName = "NAZIV";
this.dataColumn2.MaxLength = 26;
//
// bdpDeleteCommand1
//
this.bdpDeleteCommand1.CommandOptions = null;
this.bdpDeleteCommand1.CommandText = "DELETE FROM ARTIKLI WHERE ART = ? AND NAZIV = ?";
this.bdpDeleteCommand1.CommandType = System.Data.CommandType.Text;
this.bdpDeleteCommand1.Connection = this.IbConn;
this.bdpDeleteCommand1.ParameterCount = ((short)(2));
this.bdpDeleteCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("ARTOriginal", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(5)), ((byte)(0)), 5, "ART", System.Data.DataRowVersion.Original, null));
this.bdpDeleteCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("NAZIVOriginal", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(25)), ((byte)(0)), 25, "NAZIV", System.Data.DataRowVersion.Original, null));
this.bdpDeleteCommand1.SchemaName = null;
this.bdpDeleteCommand1.Transaction = null;
this.bdpDeleteCommand1.UpdatedRowSource = System.Data.UpdateRowSource.None;
//
// bdpInsertCommand1
//
this.bdpInsertCommand1.CommandOptions = null;
this.bdpInsertCommand1.CommandText = "INSERT INTO ARTIKLI (ART, NAZIV ) VALUES ( ?, ?)";
this.bdpInsertCommand1.CommandType = System.Data.CommandType.Text;
this.bdpInsertCommand1.Connection = this.IbConn;
this.bdpInsertCommand1.ParameterCount = ((short)(2));
this.bdpInsertCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("ART", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(5)), ((byte)(0)), 5, "ART", System.Data.DataRowVersion.Current, null));
this.bdpInsertCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("NAZIV", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(25)), ((byte)(0)), 25, "NAZIV", System.Data.DataRowVersion.Current, null));
this.bdpInsertCommand1.SchemaName = null;
this.bdpInsertCommand1.Transaction = null;
this.bdpInsertCommand1.UpdatedRowSource = System.Data.UpdateRowSource.None;
//
// bdpSelectCommand1
//
this.bdpSelectCommand1.CommandOptions = null;
this.bdpSelectCommand1.CommandText = "SELECT ART, NAZIV FROM ARTIKLI";
this.bdpSelectCommand1.CommandType = System.Data.CommandType.Text;
this.bdpSelectCommand1.Connection = this.IbConn;
this.bdpSelectCommand1.ParameterCount = ((short)(0));
this.bdpSelectCommand1.SchemaName = null;
this.bdpSelectCommand1.Transaction = null;
this.bdpSelectCommand1.UpdatedRowSource = System.Data.UpdateRowSource.None;
//
// bdpUpdateCommand1
//
this.bdpUpdateCommand1.CommandOptions = null;
this.bdpUpdateCommand1.CommandText = "UPDATE ARTIKLI SET ART = ?, NAZIV = ? WHERE ART = ? AND NAZIV = ?";
this.bdpUpdateCommand1.CommandType = System.Data.CommandType.Text;
this.bdpUpdateCommand1.Connection = this.IbConn;
this.bdpUpdateCommand1.ParameterCount = ((short)(4));
this.bdpUpdateCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("ART", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(5)), ((byte)(0)), 5, "ART", System.Data.DataRowVersion.Current, null));
this.bdpUpdateCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("NAZIV", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(25)), ((byte)(0)), 25, "NAZIV", System.Data.DataRowVersion.Current, null));
this.bdpUpdateCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("ARTOriginal", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(5)), ((byte)(0)), 5, "ART", System.Data.DataRowVersion.Original, null));
this.bdpUpdateCommand1.Parameters.Add(new Borland.Data.Common.BdpParameter("NAZIVOriginal", Borland.Data.Common.BdpType.String, Borland.Data.Common.BdpType.stFixed, 0, System.Data.ParameterDirection.Input, false, ((byte)(25)), ((byte)(0)), 25, "NAZIV", System.Data.DataRowVersion.Original, null));
this.bdpUpdateCommand1.SchemaName = null;
this.bdpUpdateCommand1.Transaction = null;
this.bdpUpdateCommand1.UpdatedRowSource = System.Data.UpdateRowSource.None;
//
// WinForm1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(208, 326);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.Upis);
this.Name = "WinForm1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "WinForm1";
this.Activated += new System.EventHandler(this.WinForm1_Activated);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.da)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ds)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new WinForm1());
}
private void WinForm1_Activated(object sender, System.EventArgs e)
{
da.Active = true;
}
private void Upis_Click(object sender, System.EventArgs e)
{
DataRow cRow = dataTable1.Rows[0];
cRow.BeginEdit();
// Javi.Poruka(""+cRow[0]);
cRow ["ART"]= "xxx";
cRow.EndEdit();
dataTable1.AcceptChanges();
//ds.Tables["Artikli"].Rows[0]["ART"]="xxx";
/* DataRow cRow = dataTable1.NewRow();
cRow["ART"] = "22334";
cRow["NAZIV"] = "Drugi artikal";
dataTable1.Rows.Add(cRow); */
// Close();
try {
da.Update(ds, "Artikli");
}
catch ( Exception ex) {
Javi.Poruka(ex.ToString());
}
}
}
}
|