473,657 Members | 3,041 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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Data.Ole Db;
namespace Database_Exampl e
{
/// <summary>
/// Form1
/// </summary>
public class Form1 : System.Windows. Forms.Form
{

OleDbConnection m_cnADONetConne ction =new OleDbConnection ();
OleDbDataAdapte r m_daDataAdapter = new OleDbDataAdapte r();
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 txtNewContactNa me;
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.Componen tModel.Containe r components = null;

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

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

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

#region Windows
/// <summary>

/// </summary>
private void InitializeCompo nent()
{
this.txtState = new System.Windows. Forms.TextBox() ;
this.txtContact Name = new System.Windows. Forms.TextBox() ;
this.btnMoveFir st = new System.Windows. Forms.Button();
this.btnMovePre vious = new System.Windows. Forms.Button();
this.btnMoveNex t = new System.Windows. Forms.Button();
this.btnMoveLas t = new System.Windows. Forms.Button();
this.btnSave = new System.Windows. Forms.Button();
this.txtNewCont actName = new System.Windows. Forms.TextBox() ;
this.txtNewStat e = new System.Windows. Forms.TextBox() ;
this.grpNewReco rd = new System.Windows. Forms.GroupBox( );
this.btnAddNew = new System.Windows. Forms.Button();
this.btnDelete = new System.Windows. Forms.Button();
this.grpNewReco rd.SuspendLayou t();
this.SuspendLay out();
//
// txtState
//
this.txtState.L ocation = new System.Drawing. Point(192, 40);
this.txtState.N ame = "txtState";
this.txtState.S ize = new System.Drawing. Size(320, 25);
this.txtState.T abIndex = 0;
this.txtState.T ext = "txtState";
//
// txtContactName
//
this.txtContact Name.Location = new System.Drawing. Point(40, 40);
this.txtContact Name.Name = "txtContactName ";
this.txtContact Name.Size = new System.Drawing. Size(136, 25);
this.txtContact Name.TabIndex = 1;
this.txtContact Name.Text = "txtContactName ";
//
// btnMoveFirst
//
this.btnMoveFir st.Location = new System.Drawing. Point(32, 128);
this.btnMoveFir st.Name = "btnMoveFir st";
this.btnMoveFir st.TabIndex = 2;
this.btnMoveFir st.Text = "<<";
this.btnMoveFir st.Click += new
System.EventHan dler(this.btnMo veFirst_Click);
//
// btnMovePrevious
//
this.btnMovePre vious.Location = new System.Drawing. Point(104, 128);
this.btnMovePre vious.Name = "btnMovePreviou s";
this.btnMovePre vious.TabIndex = 3;
this.btnMovePre vious.Text = "<";
this.btnMovePre vious.Click += new
System.EventHan dler(this.btnMo vePrevious_Clic k);
//
// btnMoveNext
//
this.btnMoveNex t.Location = new System.Drawing. Point(176, 128);
this.btnMoveNex t.Name = "btnMoveNex t";
this.btnMoveNex t.TabIndex = 4;
this.btnMoveNex t.Text = ">";
this.btnMoveNex t.Click += new
System.EventHan dler(this.btnMo veNext_Click);
//
// btnMoveLast
//
this.btnMoveLas t.Location = new System.Drawing. Point(248, 128);
this.btnMoveLas t.Name = "btnMoveLas t";
this.btnMoveLas t.TabIndex = 5;
this.btnMoveLas t.Text = ">>";
this.btnMoveLas t.Click += new
System.EventHan dler(this.btnMo veLast_Click);
//
// btnSave
//
this.btnSave.Lo cation = new System.Drawing. Point(32, 168);
this.btnSave.Na me = "btnSave";
this.btnSave.Si ze = new System.Drawing. Size(96, 23);
this.btnSave.Ta bIndex = 6;
this.btnSave.Te xt = "SaveUpdate ";
this.btnSave.Cl ick += new System.EventHan dler(this.btnSa ve_Click);
//
// txtNewContactNa me
//
this.txtNewCont actName.Locatio n = new System.Drawing. Point(8, 24);
this.txtNewCont actName.Name = "txtNewContactN ame";
this.txtNewCont actName.TabInde x = 8;
this.txtNewCont actName.Text = "";
//
// txtNewState
//
this.txtNewStat e.Location = new System.Drawing. Point(8, 64);
this.txtNewStat e.Name = "txtNewStat e";
this.txtNewStat e.TabIndex = 9;
this.txtNewStat e.Text = "";
//
// grpNewRecord
//
this.grpNewReco rd.Controls.Add (this.btnAddNew );
this.grpNewReco rd.Controls.Add (this.txtNewCon tactName);
this.grpNewReco rd.Controls.Add (this.txtNewSta te);
this.grpNewReco rd.Location = new System.Drawing. Point(360, 96);
this.grpNewReco rd.Name = "grpNewReco rd";
this.grpNewReco rd.Size = new System.Drawing. Size(200, 136);
this.grpNewReco rd.TabIndex = 10;
this.grpNewReco rd.TabStop = false;
this.grpNewReco rd.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.EventHan dler(this.btnAd dNew_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.EventHan dler(this.btnDe lete_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(8, 18);
this.ClientSize = new System.Drawing. Size(568, 264);
this.Controls.A dd(this.btnDele te);
this.Controls.A dd(this.grpNewR ecord);
this.Controls.A dd(this.btnSave );
this.Controls.A dd(this.btnMove Last);
this.Controls.A dd(this.btnMove Next);
this.Controls.A dd(this.btnMove Previous);
this.Controls.A dd(this.btnMove First);
this.Controls.A dd(this.txtCont actName);
this.Controls.A dd(this.txtStat e);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHan dler(this.Form1 _Load);
this.Closed += new System.EventHan dler(this.Form1 _Closed);
this.grpNewReco rd.ResumeLayout (false);
this.ResumeLayo ut(false);

}
#endregion

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

private void Form1_Load(obje ct sender, System.EventArg s e)
{

m_cnADONetConne ction.Connectio nString=@"Provi der=Microsoft.J et.OLEDB.4.0;Da ta
Source=rj.mdb;" ;
m_cnADONetConne ction.Open();

m_daDataAdapter =
new OleDbDataAdapte r("Select * From rj ",m_cnADONetCon nection);//rj.mdb
, rj table
OleDbCommandBui lder m_cbCommandBuil der =
new OleDbCommandBui lder(m_daDataAd apter);

m_daDataAdapter .Fill(m_dtConta cts);
this.ShowCurren tRecord();

}

private void Form1_Closed(ob ject sender, System.EventArg s e)
{
m_cnADONetConne ction.Close();
}

private void ShowCurrentReco rd()
{
if (m_dtContacts.R ows.Count==0)
{
txtContactName. Text = "";
txtState.Text = "";
return;
}
txtContactName. Text =
m_dtContacts.Ro ws[m_rowPosition]["date"].ToString();
txtState.Text = m_dtContacts.Ro ws[m_rowPosition]["content"].ToString();
}

private void btnMoveFirst_Cl ick(object sender, System.EventArg s e)
{
// Move to the first row and show the data.
m_rowPosition = 0;
this.ShowCurren tRecord();

}

private void btnMovePrevious _Click(object sender, System.EventArg s 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.ShowCurren tRecord();
}

}

private void btnMoveNext_Cli ck(object sender, System.EventArg s e)
{
// If not on the last row, advance one row and show the record.
if (m_rowPosition < m_dtContacts.Ro ws.Count-1)
{
m_rowPosition = m_rowPosition + 1;
this.ShowCurren tRecord();
}

}

private void btnMoveLast_Cli ck(object sender, System.EventArg s e)
{
// If there are any rows in the data table,
// move to the last and show the record.
if (m_dtContacts.R ows.Count != 0)
{
m_rowPosition = m_dtContacts.Ro ws.Count-1;
this.ShowCurren tRecord();
}

}

private void btnSave_Click(o bject sender, System.EventArg s e)
{
// If there is existing data, update it.

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

m_dtContacts.Ro ws[m_rowPosition]["date"]=txtContactName .Text;
m_dtContacts.Ro ws[m_rowPosition]["content"]=txtState.Text;
try
{
m_daDataAdapter .Update(m_dtCon tacts);//error
}
catch(System.Da ta.OleDb.OleDbE xception ex)
{
MessageBox.Show (ex.Message) ;
}
}
}

private void btnAddNew_Click (object sender, System.EventArg s e)
{
DataRow drNewRow=m_dtCo ntacts.NewRow() ;
drNewRow["date"]=txtNewContactN ame.Text;
drNewRow["content"]=txtNewState.Te xt;;
m_dtContacts.Ro ws.Add(drNewRow );
m_daDataAdapter .Update(m_dtCon tacts);
m_rowPosition = m_dtContacts.Ro ws.Count-1;
this.ShowCurren tRecord();
}

private void btnDelete_Click (object sender, System.EventArg s e)
{
// If there is data, delete the current row.
if (m_dtContacts.R ows.Count !=0)
{
m_dtContacts.Ro ws[m_rowPosition].Delete();
m_daDataAdapter .Update(m_dtCon tacts);
m_rowPosition=0 ;
this.ShowCurren tRecord();
}

}

}
}
Jul 4 '06 #1
1 1506
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***@removethi s.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
6529
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 Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
9
4397
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 the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
6
4330
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 result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
3350
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 numarray, help gives unhelpful responses:
7
5367
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 from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
5
3260
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 using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
8
3222
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 including search the internet for help, but the help is worthless. Any ideas?
10
3351
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 the worst I ever seen. I almost cannot find anything I need, including things I
1
6121
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 default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
2875
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 calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.