Suspense Member
Posts : 9 Join date : 2011-05-09
| Subject: C Sharp Question Wed Jun 29, 2011 3:49 am | |
| A I am newbie when it comes to c sharp, I am currently studying it. I get this error, I know the error is related probably with the class or namespace?
Error 1 Missing partial modifier on declaration of type 'thisisatest.DisconnectedDataform'; another partial declaration of this type exists C:\Users\hhh\Documents\Visual Studio 2008\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Program.cs 8 18 WindowsFormsApplication4
Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms;
namespace thisisatest { static class DisconnectedDataform { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new DisconnectedDataForm()); } } }
Form1.cs using System; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Windows.Forms;
namespace thisisatest {
partial class DisconnectedDataform : Form { private SqlConnection conn; private SqlDataAdapter daCustomers;
private DataSet dsCustomers; private DataGrid dgCustomers;
private const string tableName = "employees";
// initialize form with DataGrid and Button public DisconnectedDataform() { // fill dataset Initdata();
// set up datagrid dgCustomers = new DataGrid(); dgCustomers.Location = new Point(5, 5); dgCustomers.Size = new Size( this.ClientRectangle.Size.Width - 10, this.ClientRectangle.Height - 50); dgCustomers.DataSource = dsCustomers; dgCustomers.DataMember = employees;
// create update button Button btnUpdate = new Button(); btnUpdate.Text = "Update"; btnUpdate.Location = new Point( this.ClientRectangle.Width / 2 - btnUpdate.Width / 2, this.ClientRectangle.Height - (btnUpdate.Height + 10)); btnUpdate.Click += new EventHandler(btnUpdateClicked);
// make sure controls appear on form Controls.AddRange(new Control[] { dgCustomers, btnUpdate }); }
// set up ADO.NET objects public void Initdata() { // instantiate the connection conn = new SqlConnection( "Server=hhhhh\\SQLEXPRESS;DataBase=test;Integrated Security=SSPI");
// 1. instantiate a new DataSet dsCustomers = new DataSet();
// 2. init SqlDataAdapter with select command and connection daCustomers = new SqlDataAdapter( "select firstname, lastname from employees", conn);
// 3. fill in insert, update, and delete commands SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daCustomers);
// 4. fill the dataset daCustomers.Fill(dsCustomers, employees); }
// Update button was clicked public void btnUpdateClicked(object sender, EventArgs e) { // write changes back to DataBase daCustomers.Update(dsCustomers, employees); }
}
} |
|
Carbon Member
Posts : 12 Join date : 2011-03-09
| Subject: Re: C Sharp Question Wed Jun 29, 2011 3:50 am | |
| You are missing the partial keyword on your class declaration in the Program.cs file. Or just change the name of the class in the Program.cs file to be something different. (Which would be better) |
|
Suspense Member
Posts : 9 Join date : 2011-05-09
| Subject: Re: C Sharp Question Wed Jun 29, 2011 3:52 am | |
| Thanks for the reply, There is no error now, But the grid is not showing? Program.cs - Code:
-
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms;
namespace thisisatest { class DisconnectedDataform { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new DisconnectedDataForm2()); } } }
Form1.cs - Code:
-
using System; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Windows.Forms;
namespace thisisatest {
partial class DisconnectedDataForm2 : Form { private SqlConnection conn; private SqlDataAdapter daCustomers;
private DataSet dsCustomers; private DataGrid dgCustomers;
private const string tableName = "employees";
// initialize form with DataGrid and Button public void DisconnectedDataform() { // fill dataset Initdata();
// set up datagrid dgCustomers = new DataGrid(); dgCustomers.Location = new Point(5, 5); dgCustomers.Size = new Size( this.ClientRectangle.Size.Width - 10, this.ClientRectangle.Height - 50); dgCustomers.DataSource = dsCustomers; dgCustomers.DataMember = tableName;
// create update button Button btnUpdate = new Button(); btnUpdate.Text = "Update"; btnUpdate.Location = new Point( this.ClientRectangle.Width / 2 - btnUpdate.Width / 2, this.ClientRectangle.Height - (btnUpdate.Height + 10)); btnUpdate.Click += new EventHandler(btnUpdateClicked);
// make sure controls appear on form Controls.AddRange(new Control[] { dgCustomers, btnUpdate }); }
// set up ADO.NET objects public void Initdata() { // instantiate the connection conn = new SqlConnection( "Server=JEFFREY-PC\\SQLEXPRESS;DataBase=test;Integrated Security=SSPI"); // 1. instantiate a new DataSet dsCustomers = new DataSet();
// 2. init SqlDataAdapter with select command and connection daCustomers = new SqlDataAdapter( "select firstname, lastname from employees", conn);
// 3. fill in insert, update, and delete commands SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daCustomers);
// 4. fill the dataset daCustomers.Fill(dsCustomers, tableName); }
// Update button was clicked public void btnUpdateClicked(object sender, EventArgs e) { // write changes back to DataBase daCustomers.Update(dsCustomers, tableName); }
private void DisconnectedDataForm2_Load(object sender, EventArgs e) {
}
}
}
form1.designer.cs - Code:
-
namespace thisisatest { partial class DisconnectedDataForm2 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (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.SuspendLayout(); // // DisconnectedDataForm2 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Name = "DisconnectedDataForm2"; this.Text = "Form1"; this.Load += new System.EventHandler(this.DisconnectedDataForm2_Load); this.ResumeLayout(false);
}
#endregion
} }
|
|
Suspense Member
Posts : 9 Join date : 2011-05-09
| Subject: Re: C Sharp Question Wed Jun 29, 2011 3:53 am | |
| I noticed that I don't have a constructor,So I rename DisconnectedDataform() to DisconnectedDataform2(),then I put the InitializeComponent, to the constructor and it runs. I am just wondering, why I got a warning message.
warning:message
The designer can't be show for this file, because none of the classes within it can be designed. The designer inspected the following classes in the file: DisconnectedDataform----The base class "Sysetm.Object can't be designed
Also when I click the update button, I got this message:
InvalidOperationException was unhandled Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
I set up a primary key, so I don't know what is the problem? |
|
Sponsored content
| Subject: Re: C Sharp Question | |
| |
|