返回信息流using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.Odbc;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(232, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
OdbcConnection conn = new OdbcConnection("Dsn=test;uid=db2admin;pwd=ibmdb2");
conn.Open();
string command;
command = "insert into std values('zhang',10)";
OdbcCommand comm = new OdbcCommand(command, conn);
comm.ExecuteNonQuery();
conn.Close();
MessageBox.Show("执行成功");
}
}
}
这是一条镜像帖。来源:北邮人论坛 / scs / #29504同步于 2007/5/31
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SCS机器人发帖
Re: 代码
who
2007/5/31镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
OdbcConnection conn = new OdbcConnection("Dsn=good;uid=bage;pwd=861015");
conn.Open();
string command;
command = textBox1.Text;
OdbcCommand comm = new OdbcCommand(command, conn);
comm.ExecuteNonQuery();
conn.Close();
MessageBox.Show("执行成功");
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.Odbc;
namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(504, 40);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 40);
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(72, 40);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(336, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(632, 326);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
OdbcConnection conn = new OdbcConnection("Dsn=student;uid=db2admin;pwd=ibmdb2");
conn.Open();
string command;
command = textBox1.Text;
OdbcCommand comm = new OdbcCommand(command, conn);
comm.ExecuteNonQuery();
conn.Close();
MessageBox.Show("执行成功");
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 64);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "执行";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "输入命令";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(88, 112);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(192, 136);
this.listBox1.TabIndex = 2;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 152);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(48, 56);
this.button2.TabIndex = 3;
this.button2.Text = "查询";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
OdbcConnection conn = new OdbcConnection("Dsn=ee;uid=db2admin;pwd=ibmdb2");
conn.Open();
string command;
command = textBox1.Text;
OdbcCommand comm = new OdbcCommand(command, conn);
comm.ExecuteNonQuery();
MessageBox.Show("执行成功");
}
catch
{
MessageBox.Show("执行失败");
}
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
OdbcConnection conn = new OdbcConnection("Dsn=ee;uid=db2admin;pwd=ibmdb2");
conn.Open();
string command;
command = textBox1.Text;
OdbcDataAdapter odbcdata = new OdbcDataAdapter(command, conn);
DataTable table1 = new DataTable();
odbcdata.Fill(table1);
conn.Close();
foreach(DataRow i in table1.Rows)
{
listBox1.Items.Add((i[0]).ToString()+" "+(i[1]).ToString());
}
MessageBox.Show("查询成功");
}
catch
{
MessageBox.Show("查询失败");
}
}
}
}