mustish1
asked on
Run time Error
Can you please help me in that error?
namespace InsertUpdateDel
{
partial class Form1
{
/// <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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtID = new System.Windows.Forms.TextBox();
this.txtName = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.listBox2 = new System.Windows.Forms.ListBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(59, 47);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(19, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Id.";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(59, 95);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Name";
//
// txtID
//
this.txtID.Location = new System.Drawing.Point(149, 47);
this.txtID.Name = "txtID";
this.txtID.Size = new System.Drawing.Size(100, 20);
this.txtID.TabIndex = 2;
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(149, 95);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(100, 20);
this.txtName.TabIndex = 3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(149, 145);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Insert";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox2
//
this.listBox2.FormattingEnabled = true;
this.listBox2.Location = new System.Drawing.Point(479, 47);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(138, 160);
this.listBox2.TabIndex = 6;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(335, 19);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(16, 13);
this.label3.TabIndex = 7;
this.label3.Text = "Id";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(524, 19);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(35, 13);
this.label4.TabIndex = 8;
this.label4.Text = "Name";
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(318, 47);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(133, 160);
this.listBox1.TabIndex = 9;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(906, 314);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.listBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtName);
this.Controls.Add(this.txtID);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Insert Update Delete";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtID;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ListBox listBox1;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace InsertUpdateDel
{
public partial class Form1 : Form
{
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Lenovo\Documents\Visual Studio 2012\Projects\InsertUpdateDel\InsertUpdateDel\Database1.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader sd;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cmd.Connection = cn;
loadlist();
}
private void button1_Click(object sender, EventArgs e)
{
if (txtID.Text != "" & txtName.Text != "")
{
cn.Open();
cmd.CommandText = "Insert into info(id, name) values ('" +txtID.Text+"', '" +txtName.Text+"')";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Record Inserted", "Programming");
cn.Close();
txtID.Text="";
txtName.Text="";
loadlist();
}
}
private void loadlist()
{
listBox1.Items.Clear();
listBox2.Items.Clear();
cn.Open();
cmd.CommandText = "select * from info";
sd = cmd.ExecuteReader();
if (sd.HasRows)
{
while (sd.Read())
{
listBox1.Items.Add(sd[0].ToString());
listBox2.Items.Add(sd[0].ToString());
}
}
cn.Close();
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox i = sender as ListBox;
if (i.SelectedIndex != -1)
{
listBox1.SelectedIndex = i.SelectedIndex;
listBox2.SelectedIndex = i.SelectedIndex;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.