473,503 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ado.net help

it is very strange£¬
when i pressSaveUpdate£¬if only change txtState£¬it's not problem£¬

but if i change txtContactName,it will be show error£¬

rj.mdb £º
id auto
date string
content string

£¿
thanks!

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace Database_Example
{
/// <summary>
/// Form1
/// </summary>
public class Form1 : System.Windows.Forms.Form
{

OleDbConnection m_cnADONetConnection =new OleDbConnection();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
DataTable m_dtContacts = new DataTable();
int m_rowPosition = 0;
private System.Windows.Forms.TextBox txtState;
private System.Windows.Forms.TextBox txtContactName;
private System.Windows.Forms.Button btnMoveFirst;
private System.Windows.Forms.Button btnMovePrevious;
private System.Windows.Forms.Button btnMoveNext;
private System.Windows.Forms.Button btnMoveLast;
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.TextBox txtNewContactName;
private System.Windows.Forms.TextBox txtNewState;
private System.Windows.Forms.GroupBox grpNewRecord;
private System.Windows.Forms.Button btnAddNew;
private System.Windows.Forms.Button btnDelete;

/// <summary>
/// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ
//
InitializeComponent();

//
// TODO: ÔÚ InitializeComponent µ÷ÓúóÌí¼ÓÈκι¹Ô캯Êý´úÂë
//
}

/// <summary>
/// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows
/// <summary>

/// </summary>
private void InitializeComponent()
{
this.txtState = new System.Windows.Forms.TextBox();
this.txtContactName = new System.Windows.Forms.TextBox();
this.btnMoveFirst = new System.Windows.Forms.Button();
this.btnMovePrevious = new System.Windows.Forms.Button();
this.btnMoveNext = new System.Windows.Forms.Button();
this.btnMoveLast = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button();
this.txtNewContactName = new System.Windows.Forms.TextBox();
this.txtNewState = new System.Windows.Forms.TextBox();
this.grpNewRecord = new System.Windows.Forms.GroupBox();
this.btnAddNew = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.grpNewRecord.SuspendLayout();
this.SuspendLayout();
//
// txtState
//
this.txtState.Location = new System.Drawing.Point(192, 40);
this.txtState.Name = "txtState";
this.txtState.Size = new System.Drawing.Size(320, 25);
this.txtState.TabIndex = 0;
this.txtState.Text = "txtState";
//
// txtContactName
//
this.txtContactName.Location = new System.Drawing.Point(40, 40);
this.txtContactName.Name = "txtContactName";
this.txtContactName.Size = new System.Drawing.Size(136, 25);
this.txtContactName.TabIndex = 1;
this.txtContactName.Text = "txtContactName";
//
// btnMoveFirst
//
this.btnMoveFirst.Location = new System.Drawing.Point(32, 128);
this.btnMoveFirst.Name = "btnMoveFirst";
this.btnMoveFirst.TabIndex = 2;
this.btnMoveFirst.Text = "<<";
this.btnMoveFirst.Click += new
System.EventHandler(this.btnMoveFirst_Click);
//
// btnMovePrevious
//
this.btnMovePrevious.Location = new System.Drawing.Point(104, 128);
this.btnMovePrevious.Name = "btnMovePrevious";
this.btnMovePrevious.TabIndex = 3;
this.btnMovePrevious.Text = "<";
this.btnMovePrevious.Click += new
System.EventHandler(this.btnMovePrevious_Click);
//
// btnMoveNext
//
this.btnMoveNext.Location = new System.Drawing.Point(176, 128);
this.btnMoveNext.Name = "btnMoveNext";
this.btnMoveNext.TabIndex = 4;
this.btnMoveNext.Text = ">";
this.btnMoveNext.Click += new
System.EventHandler(this.btnMoveNext_Click);
//
// btnMoveLast
//
this.btnMoveLast.Location = new System.Drawing.Point(248, 128);
this.btnMoveLast.Name = "btnMoveLast";
this.btnMoveLast.TabIndex = 5;
this.btnMoveLast.Text = ">>";
this.btnMoveLast.Click += new
System.EventHandler(this.btnMoveLast_Click);
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(32, 168);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(96, 23);
this.btnSave.TabIndex = 6;
this.btnSave.Text = "SaveUpdate";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// txtNewContactName
//
this.txtNewContactName.Location = new System.Drawing.Point(8, 24);
this.txtNewContactName.Name = "txtNewContactName";
this.txtNewContactName.TabIndex = 8;
this.txtNewContactName.Text = "";
//
// txtNewState
//
this.txtNewState.Location = new System.Drawing.Point(8, 64);
this.txtNewState.Name = "txtNewState";
this.txtNewState.TabIndex = 9;
this.txtNewState.Text = "";
//
// grpNewRecord
//
this.grpNewRecord.Controls.Add(this.btnAddNew);
this.grpNewRecord.Controls.Add(this.txtNewContactN ame);
this.grpNewRecord.Controls.Add(this.txtNewState);
this.grpNewRecord.Location = new System.Drawing.Point(360, 96);
this.grpNewRecord.Name = "grpNewRecord";
this.grpNewRecord.Size = new System.Drawing.Size(200, 136);
this.grpNewRecord.TabIndex = 10;
this.grpNewRecord.TabStop = false;
this.grpNewRecord.Text = "New Contact";
//
// btnAddNew
//
this.btnAddNew.Location = new System.Drawing.Point(32, 104);
this.btnAddNew.Name = "btnAddNew";
this.btnAddNew.TabIndex = 10;
this.btnAddNew.Text = "Add";
this.btnAddNew.Click += new System.EventHandler(this.btnAddNew_Click);
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(240, 168);
this.btnDelete.Name = "btnDelete";
this.btnDelete.TabIndex = 11;
this.btnDelete.Text = "Delete";
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(568, 264);
this.Controls.Add(this.btnDelete);
this.Controls.Add(this.grpNewRecord);
this.Controls.Add(this.btnSave);
this.Controls.Add(this.btnMoveLast);
this.Controls.Add(this.btnMoveNext);
this.Controls.Add(this.btnMovePrevious);
this.Controls.Add(this.btnMoveFirst);
this.Controls.Add(this.txtContactName);
this.Controls.Add(this.txtState);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
this.grpNewRecord.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// Ó¦ÓóÌÐòµÄÖ÷Èë¿Úµã¡£
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

m_cnADONetConnection.ConnectionString=@"Provider=M icrosoft.Jet.OLEDB.4.0;Data
Source=rj.mdb;";
m_cnADONetConnection.Open();

m_daDataAdapter =
new OleDbDataAdapter("Select * From rj ",m_cnADONetConnection);//rj.mdb
, rj table
OleDbCommandBuilder m_cbCommandBuilder =
new OleDbCommandBuilder(m_daDataAdapter);

m_daDataAdapter.Fill(m_dtContacts);
this.ShowCurrentRecord();

}

private void Form1_Closed(object sender, System.EventArgs e)
{
m_cnADONetConnection.Close();
}

private void ShowCurrentRecord()
{
if (m_dtContacts.Rows.Count==0)
{
txtContactName.Text = "";
txtState.Text = "";
return;
}
txtContactName.Text =
m_dtContacts.Rows[m_rowPosition]["date"].ToString();
txtState.Text = m_dtContacts.Rows[m_rowPosition]["content"].ToString();
}

private void btnMoveFirst_Click(object sender, System.EventArgs e)
{
// Move to the first row and show the data.
m_rowPosition = 0;
this.ShowCurrentRecord();

}

private void btnMovePrevious_Click(object sender, System.EventArgs e)
{
// If not at the first row, go back one row and show the record.
if (m_rowPosition != 0)
{
m_rowPosition = m_rowPosition-1;
this.ShowCurrentRecord();
}

}

private void btnMoveNext_Click(object sender, System.EventArgs e)
{
// If not on the last row, advance one row and show the record.
if (m_rowPosition < m_dtContacts.Rows.Count-1)
{
m_rowPosition = m_rowPosition + 1;
this.ShowCurrentRecord();
}

}

private void btnMoveLast_Click(object sender, System.EventArgs e)
{
// If there are any rows in the data table,
// move to the last and show the record.
if (m_dtContacts.Rows.Count != 0)
{
m_rowPosition = m_dtContacts.Rows.Count-1;
this.ShowCurrentRecord();
}

}

private void btnSave_Click(object sender, System.EventArgs e)
{
// If there is existing data, update it.

if(m_dtContacts.Rows.Count!=0)
{

m_dtContacts.Rows[m_rowPosition]["date"]=txtContactName.Text;
m_dtContacts.Rows[m_rowPosition]["content"]=txtState.Text;
try
{
m_daDataAdapter.Update(m_dtContacts);//error
}
catch(System.Data.OleDb.OleDbException ex)
{
MessageBox.Show(ex.Message) ;
}
}
}

private void btnAddNew_Click(object sender, System.EventArgs e)
{
DataRow drNewRow=m_dtContacts.NewRow();
drNewRow["date"]=txtNewContactName.Text;
drNewRow["content"]=txtNewState.Text;;
m_dtContacts.Rows.Add(drNewRow);
m_daDataAdapter.Update(m_dtContacts);
m_rowPosition = m_dtContacts.Rows.Count-1;
this.ShowCurrentRecord();
}

private void btnDelete_Click(object sender, System.EventArgs e)
{
// If there is data, delete the current row.
if (m_dtContacts.Rows.Count !=0)
{
m_dtContacts.Rows[m_rowPosition].Delete();
m_daDataAdapter.Update(m_dtContacts);
m_rowPosition=0;
this.ShowCurrentRecord();
}

}

}
}
Jul 4 '06 #1
1 1500
Hi Michael,
when i pressSaveUpdate£¬if only change txtState£¬it's not problem£¬
but if i change txtContactName,it will be show error£¬
It would help if you would let us know the error message you get. If I would
guess, it is some kind of SQL error or security and/or constraint error, but
could of course be something else too.

Also, why do you call a field in the database a "date" and then use it as
"contact name" in the code? That's confusing.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Jul 5 '06 #2

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

Similar topics

21
6485
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
4374
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
4303
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
3322
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
5343
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
3249
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
3206
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
3327
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
6111
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
2848
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.