Click here to Skip to main content
15,917,329 members
Home / Discussions / Database
   

Database

 
QuestionMSDE Bootrappers Pin
JacquesDP6-Aug-06 23:46
JacquesDP6-Aug-06 23:46 
AnswerRe: MSDE Bootrappers Pin
Suresh Kumar.A13-Aug-06 1:36
Suresh Kumar.A13-Aug-06 1:36 
QuestionNHibernate? Pin
YOMATA6-Aug-06 22:34
YOMATA6-Aug-06 22:34 
QuestionTree View Menu in HTML Pin
skysunil6-Aug-06 20:59
skysunil6-Aug-06 20:59 
AnswerRe: Tree View Menu in HTML Pin
Colin Angus Mackay6-Aug-06 22:16
Colin Angus Mackay6-Aug-06 22:16 
QuestionSetup .ini in SQL server 200 Pin
pratap ankesh6-Aug-06 20:00
pratap ankesh6-Aug-06 20:00 
AnswerRe: Setup .ini in SQL server 200 Pin
JacquesDP6-Aug-06 23:42
JacquesDP6-Aug-06 23:42 
Questionconnection pro again Pin
skyeddie6-Aug-06 0:49
skyeddie6-Aug-06 0:49 
hi all i have this pro on hand now.. i have downloaded some sample database applications from the internet..however when i want to debug it i gives me the error--An unhandled exception of type "system.Data.OleDb.OledbException" occurred in system.data.dll

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 description for Form1.
///

public class fclsMain : System.Windows.Forms.Form
{
OleDbConnection m_cnADONewConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
DataTable m_dtContacts = new DataTable();
int m_rowPosition = 0;
private System.Windows.Forms.TextBox txtContactName;
private System.Windows.Forms.TextBox txtState;
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.GroupBox grpNewRecord;
private System.Windows.Forms.TextBox txtNewContactName;
private System.Windows.Forms.TextBox txtNewState;
private System.Windows.Forms.Button btnAddNew;
private System.Windows.Forms.Button btnDelete;

///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public fclsMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.txtContactName = new System.Windows.Forms.TextBox();
this.txtState = 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.grpNewRecord = new System.Windows.Forms.GroupBox();
this.txtNewContactName = new System.Windows.Forms.TextBox();
this.txtNewState = new System.Windows.Forms.TextBox();
this.btnAddNew = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.grpNewRecord.SuspendLayout();
this.SuspendLayout();
//
// txtContactName
//
this.txtContactName.Location = new System.Drawing.Point(48, 112);
this.txtContactName.Name = "txtContactName";
this.txtContactName.Size = new System.Drawing.Size(112, 20);
this.txtContactName.TabIndex = 0;
this.txtContactName.Text = "";
//
// txtState
//
this.txtState.Location = new System.Drawing.Point(168, 112);
this.txtState.Name = "txtState";
this.txtState.Size = new System.Drawing.Size(80, 20);
this.txtState.TabIndex = 1;
this.txtState.Text = "";
//
// btnMoveFirst
//
this.btnMoveFirst.Location = new System.Drawing.Point(16, 152);
this.btnMoveFirst.Name = "btnMoveFirst";
this.btnMoveFirst.Size = new System.Drawing.Size(32, 23);
this.btnMoveFirst.TabIndex = 2;
this.btnMoveFirst.Text = "<<";
this.btnMoveFirst.Click += new System.EventHandler(this.btnMoveFirst_Click);
//
// btnMovePrevious
//
this.btnMovePrevious.Location = new System.Drawing.Point(56, 152);
this.btnMovePrevious.Name = "btnMovePrevious";
this.btnMovePrevious.Size = new System.Drawing.Size(32, 23);
this.btnMovePrevious.TabIndex = 3;
this.btnMovePrevious.Text = "<";
this.btnMovePrevious.Click += new System.EventHandler(this.btnMovePrevious_Click);
//
// btnMoveNext
//
this.btnMoveNext.Location = new System.Drawing.Point(96, 152);
this.btnMoveNext.Name = "btnMoveNext";
this.btnMoveNext.Size = new System.Drawing.Size(32, 23);
this.btnMoveNext.TabIndex = 4;
this.btnMoveNext.Text = ">";
this.btnMoveNext.Click += new System.EventHandler(this.btnMoveNext_Click);
//
// btnMoveLast
//
this.btnMoveLast.Location = new System.Drawing.Point(136, 152);
this.btnMoveLast.Name = "btnMoveLast";
this.btnMoveLast.Size = new System.Drawing.Size(32, 23);
this.btnMoveLast.TabIndex = 5;
this.btnMoveLast.Text = ">>";
this.btnMoveLast.Click += new System.EventHandler(this.btnMoveLast_Click);
//
// btnSave
//
this.btnSave.Location = new System.Drawing.Point(176, 152);
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(40, 23);
this.btnSave.TabIndex = 6;
this.btnSave.Text = "Save";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// grpNewRecord
//
this.grpNewRecord.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnAddNew,
this.txtNewState,
this.txtNewContactName});
this.grpNewRecord.Location = new System.Drawing.Point(16, 192);
this.grpNewRecord.Name = "grpNewRecord";
this.grpNewRecord.Size = new System.Drawing.Size(264, 64);
this.grpNewRecord.TabIndex = 7;
this.grpNewRecord.TabStop = false;
this.grpNewRecord.Text = "New Contact";
//
// txtNewContactName
//
this.txtNewContactName.Location = new System.Drawing.Point(8, 24);
this.txtNewContactName.Name = "txtNewContactName";
this.txtNewContactName.Size = new System.Drawing.Size(112, 20);
this.txtNewContactName.TabIndex = 0;
this.txtNewContactName.Text = "";
//
// txtNewState
//
this.txtNewState.Location = new System.Drawing.Point(126, 24);
this.txtNewState.Name = "txtNewState";
this.txtNewState.Size = new System.Drawing.Size(80, 20);
this.txtNewState.TabIndex = 1;
this.txtNewState.Text = "";
//
// btnAddNew
//
this.btnAddNew.Location = new System.Drawing.Point(214, 24);
this.btnAddNew.Name = "btnAddNew";
this.btnAddNew.Size = new System.Drawing.Size(40, 23);
this.btnAddNew.TabIndex = 2;
this.btnAddNew.Text = "Add";
this.btnAddNew.Click += new System.EventHandler(this.btnAddNew_Click);
//
// btnDelete
//
this.btnDelete.Location = new System.Drawing.Point(224, 152);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(56, 23);
this.btnDelete.TabIndex = 8;
this.btnDelete.Text = "Delete";
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
//
// fclsMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnDelete,
this.grpNewRecord,
this.btnSave,
this.btnMoveLast,
this.btnMoveNext,
this.btnMovePrevious,
this.btnMoveFirst,
this.txtState,
this.txtContactName});
this.Name = "fclsMain";
this.Text = "Database Example";
this.Load += new System.EventHandler(this.fclsMain_Load);
this.Closed += new System.EventHandler(this.fclsMain_Closed);
this.grpNewRecord.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new fclsMain());
}

private void fclsMain_Load(object sender, System.EventArgs e)
{
m_cnADONewConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\contacts.mdb";
m_daDataAdapter =
new OleDbDataAdapter("Select * From Contacts",m_cnADONewConnection);
OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtContacts);
this.ShowCurrentRecord();
}

private void fclsMain_Closed(object sender, System.EventArgs e)
{
m_cnADONewConnection.Close();
}
private void ShowCurrentRecord()
{
if (m_dtContacts.Rows.Count==0)
{
txtContactName.Text = "";
txtState.Text = "";
return;
}
txtContactName.Text =
m_dtContacts.Rows[m_rowPosition]["ContactName"].ToString();
txtState.Text = m_dtContacts.Rows[m_rowPosition]["State"].ToString();
}

private void btnMoveFirst_Click(object sender, System.EventArgs e)
{
m_rowPosition = 0;
this.ShowCurrentRecord();
}

private void btnMovePrevious_Click(object sender, System.EventArgs e)
{
if (!(m_rowPosition == 0))
{
m_rowPosition = m_rowPosition-1;
this.ShowCurrentRecord();
}

}

private void btnMoveNext_Click(object sender, System.EventArgs e)
{
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(!(m_dtContacts.Rows.Count==0))
{
m_rowPosition = m_dtContacts.Rows.Count-1;
this.ShowCurrentRecord();
}

}

private void btnSave_Click(object sender, System.EventArgs e)
{
if (!(m_dtContacts.Rows.Count==0))
{
m_dtContacts.Rows[m_rowPosition]["ContactName"]= txtContactName.Text;
m_dtContacts.Rows[m_rowPosition]["State"] = txtState.Text;
m_daDataAdapter.Update(m_dtContacts);
}

}

private void btnAddNew_Click(object sender, System.EventArgs e)
{
DataRow drNewRow = m_dtContacts.NewRow();
drNewRow["ContactName"] = txtNewContactName.Text;
drNewRow["State"] = 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 (!(m_dtContacts.Rows.Count==0))
{
m_dtContacts.Rows[m_rowPosition].Delete();
m_daDataAdapter.Update(m_dtContacts);
m_rowPosition=0;
this.ShowCurrentRecord();
}

}



}
}





does this errors occur due to where the dB file is located..is it correct? can someone out there help will this pro? and maybe guide me to correcting it ..thanks in advance..
the whole chunk of codes is written below,the pro is highlighted in bold...thanks in advance





one of the ans i got is entering cnADONewConnection.Open();
before m_daDataAdapter.Fill(m_dtContacts);
but i got an error like this C:\Documents and Settings\STUDENT\Desktop\Database Example\Form1.cs(235): The type or namespace name 'cnADONewConnection' could not be found (are you missing a using directive or an assembly reference?)


can anyone please give me more detailed help as im really new to this
AnswerRe: connection pro again Pin
Christian Graus6-Aug-06 1:16
protectorChristian Graus6-Aug-06 1:16 
AnswerRe: connection pro again Pin
Rob Graham6-Aug-06 4:26
Rob Graham6-Aug-06 4:26 
GeneralRe: connection pro again Pin
skyeddie6-Aug-06 19:59
skyeddie6-Aug-06 19:59 
GeneralRe: connection pro again Pin
Rob Graham7-Aug-06 3:43
Rob Graham7-Aug-06 3:43 
Questioninserting data thru web forms Pin
Kunal P6-Aug-06 0:23
Kunal P6-Aug-06 0:23 
AnswerRe: inserting data thru web forms Pin
Christian Graus6-Aug-06 1:21
protectorChristian Graus6-Aug-06 1:21 
GeneralRe: inserting data thru web forms Pin
Kunal P7-Aug-06 6:40
Kunal P7-Aug-06 6:40 
QuestionHow to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#5-Aug-06 21:10
Rocky#5-Aug-06 21:10 
AnswerRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Christian Graus6-Aug-06 1:22
protectorChristian Graus6-Aug-06 1:22 
AnswerRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#6-Aug-06 9:25
Rocky#6-Aug-06 9:25 
GeneralRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#6-Aug-06 9:33
Rocky#6-Aug-06 9:33 
QuestionRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#6-Aug-06 9:38
Rocky#6-Aug-06 9:38 
AnswerRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Izak -7-Aug-06 0:12
Izak -7-Aug-06 0:12 
GeneralRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#7-Aug-06 3:23
Rocky#7-Aug-06 3:23 
QuestionRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#7-Aug-06 3:28
Rocky#7-Aug-06 3:28 
AnswerRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
Rocky#7-Aug-06 20:04
Rocky#7-Aug-06 20:04 
GeneralRe: How to iterate thru all the elements of Datagrid (windows forms) Pin
_AK_7-Aug-06 20:12
_AK_7-Aug-06 20:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.