Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
GeneralRe: parameterized query Pin
jdkulkarni25-Aug-05 19:29
jdkulkarni25-Aug-05 19:29 
GeneralRe: parameterized query Pin
nidhelp25-Aug-05 19:40
nidhelp25-Aug-05 19:40 
GeneralRe: parameterized query Pin
jdkulkarni25-Aug-05 19:47
jdkulkarni25-Aug-05 19:47 
GeneralRe: parameterized query Pin
nidhelp25-Aug-05 20:02
nidhelp25-Aug-05 20:02 
GeneralRe: parameterized query Pin
jdkulkarni25-Aug-05 20:47
jdkulkarni25-Aug-05 20:47 
GeneralRe: parameterized query Pin
nidhelp25-Aug-05 20:58
nidhelp25-Aug-05 20:58 
GeneralRe: parameterized query Pin
nidhelp25-Aug-05 21:19
nidhelp25-Aug-05 21:19 
GeneralRe: parameterized query Pin
jdkulkarni25-Aug-05 23:48
jdkulkarni25-Aug-05 23:48 
Hi, I did not receive the database. But the code looks ok. I'm sending sample code with this answer. I'm simple code snippet.
/*****************FORM1********************************/
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace dono

{

///

/// Summary description for Form1.

///


public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.Button button1;

private System.Windows.Forms.TextBox textBox1;

private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

private System.Data.OleDb.OleDbConnection oleDbConnection1;

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;

public Form1()

{

//

// 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.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(256, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 112);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// oleDbDataAdapter1
//
this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Patients", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ContactID", "ContactID"),
new System.Data.Common.DataColumnMapping("FirstName", "FirstName")})});
this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
//
// oleDbDeleteCommand1
//
this.oleDbDeleteCommand1.CommandText = "DELETE FROM Patients WHERE (ContactID = ?) AND (FirstName = ? OR ? IS NULL AND Fi" +
"rstName IS NULL)";
this.oleDbDeleteCommand1.Connection = this.oleDbConnection1;
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ContactID", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactID", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_FirstName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FirstName", System.Data.DataRowVersion.Original, null));
this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_FirstName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FirstName", System.Data.DataRowVersion.Original, null));
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=""G:\database.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
//
// oleDbInsertCommand1
//
this.oleDbInsertCommand1.CommandText = "INSERT INTO Patients(ContactID, FirstName) VALUES (?, ?)";
this.oleDbInsertCommand1.Connection = this.oleDbConnection1;
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ContactID", System.Data.OleDb.OleDbType.VarWChar, 50, "ContactID"));
this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("FirstName", System.Data.OleDb.OleDbType.VarWChar, 50, "FirstName"));
//
// oleDbSelectCommand1
//
this.oleDbSelectCommand1.CommandText = "SELECT ContactID, FirstName FROM Patients WHERE (ContactID = ?)";
this.oleDbSelectCommand1.Connection = this.oleDbConnection1;
this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ContactID", System.Data.OleDb.OleDbType.VarWChar, 50, "ContactID"));
//
// oleDbUpdateCommand1
//
this.oleDbUpdateCommand1.CommandText = "UPDATE Patients SET ContactID = ?, FirstName = ? WHERE (ContactID = ?) AND (First" +
"Name = ? OR ? IS NULL AND FirstName IS NULL)";
this.oleDbUpdateCommand1.Connection = this.oleDbConnection1;
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("ContactID", System.Data.OleDb.OleDbType.VarWChar, 50, "ContactID"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("FirstName", System.Data.OleDb.OleDbType.VarWChar, 50, "FirstName"));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_ContactID", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactID", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_FirstName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FirstName", System.Data.DataRowVersion.Original, null));
this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_FirstName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FirstName", System.Data.DataRowVersion.Original, null));
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(544, 230);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

#endregion

///

/// The main entry point for the application.

///


[STAThread]

static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.textBox1.Text = "I got the value";
this.Hide();
frm.Show();
}
}

}
/*************************************************/

/*****************FORM2********************************/

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace dono

{

///

/// Summary description for Form2.

///


public class Form2 : System.Windows.Forms.Form

{

public System.Windows.Forms.TextBox textBox1;

private System.Windows.Forms.TextBox textBox2;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;

public Form2()

{

//

// 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.textBox1 = new System.Windows.Forms.TextBox();

this.textBox2 = new System.Windows.Forms.TextBox();

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.SuspendLayout();

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(216, 72);

this.textBox1.Name = "textBox1";

this.textBox1.TabIndex = 0;

this.textBox1.Text = "textBox1";

//

// textBox2

//

this.textBox2.Location = new System.Drawing.Point(216, 120);

this.textBox2.Name = "textBox2";

this.textBox2.TabIndex = 1;

this.textBox2.Text = "textBox2";

//

// label1

//

this.label1.Location = new System.Drawing.Point(112, 72);

this.label1.Name = "label1";

this.label1.TabIndex = 3;

this.label1.Text = "contactID";

//

// label2

//

this.label2.Location = new System.Drawing.Point(112, 120);

this.label2.Name = "label2";

this.label2.TabIndex = 4;

this.label2.Text = "name";

//

// Form2

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(440, 246);

this.Controls.Add(this.label2);

this.Controls.Add(this.label1);

this.Controls.Add(this.textBox2);

this.Controls.Add(this.textBox1);

this.Name = "Form2";

this.Text = "Form2";

this.ResumeLayout(false);

}

#endregion

}
}
/*************************************************/

It is as simple as the code in button click.

Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
GeneralRe: parameterized query Pin
nidhelp26-Aug-05 5:42
nidhelp26-Aug-05 5:42 
GeneralRe: parameterized query Pin
jdkulkarni28-Aug-05 18:19
jdkulkarni28-Aug-05 18:19 
GeneralRe: parameterized query Pin
Luis Alonso Ramos25-Aug-05 19:43
Luis Alonso Ramos25-Aug-05 19:43 
GeneralRe: parameterized query Pin
jdkulkarni25-Aug-05 19:54
jdkulkarni25-Aug-05 19:54 
GeneralRe: parameterized query Pin
Daniel Turini26-Aug-05 2:12
Daniel Turini26-Aug-05 2:12 
GeneralRe: parameterized query Pin
Not Active26-Aug-05 3:08
mentorNot Active26-Aug-05 3:08 
GeneralRe: parameterized query Pin
jdkulkarni26-Aug-05 3:23
jdkulkarni26-Aug-05 3:23 
GeneralRe: parameterized query Pin
Not Active26-Aug-05 3:33
mentorNot Active26-Aug-05 3:33 
AnswerRe: parameterized query Pin
Luis Alonso Ramos26-Aug-05 3:54
Luis Alonso Ramos26-Aug-05 3:54 
GeneralRe: parameterized query Pin
nidhelp26-Aug-05 6:10
nidhelp26-Aug-05 6:10 
QuestionTEXT BOX TEXT TO DOUBLE? Pin
...---...25-Aug-05 14:56
...---...25-Aug-05 14:56 
AnswerRe: TEXT BOX TEXT TO DOUBLE? Pin
Luis Alonso Ramos25-Aug-05 16:49
Luis Alonso Ramos25-Aug-05 16:49 
GeneralRe: TEXT BOX TEXT TO DOUBLE? Pin
...---...25-Aug-05 17:02
...---...25-Aug-05 17:02 
JokeRe: TEXT BOX TEXT TO DOUBLE? Pin
Luis Alonso Ramos25-Aug-05 18:03
Luis Alonso Ramos25-Aug-05 18:03 
QuestionRetrieve the value of Inout parameter Pin
tsramkumar25-Aug-05 11:35
tsramkumar25-Aug-05 11:35 
AnswerRe: Retrieve the value of Inout parameter Pin
miah alom25-Aug-05 11:42
miah alom25-Aug-05 11:42 
GeneralRe: Retrieve the value of Inout parameter Pin
tsramkumar25-Aug-05 11:46
tsramkumar25-Aug-05 11:46 

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.