关于dbgrid (10分)

  • 主题发起人 主题发起人 tianxing78
  • 开始时间 开始时间
T

tianxing78

Unregistered / Unconfirmed
GUEST, unregistred user!
关于dbgrid
环境:vs.net
我想用dbgrid来显示sql server2000中的一个表的内容。该如何连接?
 
[^]
问的怎么简单,怎么没人答???
 
是啊,怎么没人回答呢,是不是问题太简单了!!!
 
问题是这里不是.net论坛阿。
要是delphi早就有人回答了。
 
是delphi就有人答啦!
 
Dim ObjConn As SqlClient.SqlConnection
Dim StSqlString As String
Dim ConnStSql As String
StSqlString = "workstation id=SOFTWARE;packet size=4096;user id=sa;password=;data source=software;persist security info=False;initial catalog=ws"
ObjConn = New SqlClient.SqlConnection(StSqlString)
ObjConn.Open()
StSqlString = "select top 1 * from operation where username='XXand password='AA
Dim ObjDataAdapter As SqlClient.SqlDataAdapter
Dim ObjDataSet As New Data.DataSet
ObjDataAdapter = New SqlClient.SqlDataAdapter(StSqlString, ObjConn)
ObjDataAdapter.Fill(ObjDataSet, "Operation")
Me.DataGrid1.DataSource = ObjDataSet.Tables("operation").DefaultView
Me.DataGrid1.DataBind()
 
StSqlString = "select top 1 * from operation where username='XX' and password='AA'
这一句少了两个引号
见谅
 
来晚了[^]
 
// project created on 2003-8-10 at 17:28
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Configuration;
using FirebirdSql.Data.Firebird;
namespace MyFormProject
{
class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button;
private System.Windows.Forms.DataGrid dataGrid;
public MainForm()
{
InitializeComponent();
}

// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
//do
NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
void buttonClick(object sender, System.EventArgs e)
{

string myConnectionString =
"User=SYSDBA;" +
"Password=masterkey;" +
"Database=G://haiguan//ibase//SYSTEM.GDB;" +
"DataSource=localhost;" +
"Port=3050;" +
"Dialect=3"+

"Connection lifetime=30;" +
"Pooling=true;" +
"Packet Size=8192";


FbConnection fb = new FbConnection(myConnectionString);
fb.Open();
FbDataAdapter fda = new FbDataAdapter();
FbTransaction ft = fb.begin
Transaction();
fda.SelectCommand = new FbCommand("select * from JYDW",fb,ft);
DataSet ds = new DataSet();
fda.Fill(ds);
dataGrid.DataSource = ds;
//dataGrid.DataBind();
fb.Close();
}

void InitializeComponent() {
this.dataGrid = new System.Windows.Forms.DataGrid();
this.button = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).begin
Init();
this.SuspendLayout();
this.dataGrid.SuspendLayout();
//
// dataGrid
//
this.dataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid.DataMember = "";
this.dataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid.Location = new System.Drawing.Point(24, 24);
this.dataGrid.Name = "dataGrid";
this.dataGrid.Size = new System.Drawing.Size(232, 160);
this.dataGrid.TabIndex = 0;
//
// button
//
this.button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button.Location = new System.Drawing.Point(56, 216);
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(96, 24);
this.button.TabIndex = 1;
this.button.Text = "button";
this.button.Click += new System.EventHandler(this.buttonClick);
//
// MainForm
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button,
this.dataGrid});
this.Text = "This is my form";
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
this.dataGrid.ResumeLayout(false);
this.ResumeLayout(false);
}

[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
}
}


////////////我用的是firebird1。5rc5。
//到firebird.sourceforge.net下载.net驱动
//csc /r:F:/w2k/FirebirdNetProvider/FirebirdSql.Data.Firebird.dll;System.Data.dll %1是编译命令。
//
 
后退
顶部