读到一个string 里面不就可以了
解决方案 »
- 数据库 备份 还原
- vs.net2010带的那个sql server express 2008是哪个版本?
- 请问为什么在一个循环里对LABEL的TEXT不断赋值,可LABEL却不能实时更新响应,为什么呢?谢谢~
- 如何查询 数据并 把结果添到 datagridview 并对其中的 -内容统计
- 来者,智者加分!我觉得微软的Visual SourceSafe真是变态的不行,各位看看?
- 请帮忙看看这个Form_Load那写错了,为什么就是不执行呢?????????????????????????
- 分享个读取INI文件类 不要分 需要的下载
- socket问题2
- 难道是微软的BUG??请问谁能解决啊?
- 结构体赋值问题
- 请问各位高手,怎样用VC#下载FTP的文件
- 本人想转行了,准备再去自考一个本科文凭,什么专业实用呀!
String strSQL = "SELECT Title FROM Employees"; SqlConnection cn = null;
SqlCommand com = null;
SqlDataReader rd = null;
try
{
cn = new SqlConnection(strCn);
cn.Open();
com = new SqlCommand(strSQL,cn); rd = com.ExecuteReader(); if( rd.Read())
{
String str = rd["Title"].ToString();
textBox1.Text = str;
}
}
catch(Exception ee)
{
//错误处理
}
finally
{
if(rd != null)
rd.Close(); if(com != null)
com.Dispose(); if(cn != null)
cn.Close();
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace WindowsApplication6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private SqlConnection conn;
private SqlDataAdapter ad;
private DataSet ds;
private DataTable dt;
private int i;
private SqlCommandBuilder cmdB;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
conn=new SqlConnection("server=b02;uid=xcj;pwd=xcj;database=pubs");
ad=new SqlDataAdapter("select * from student",conn);
cmdB=new SqlCommandBuilder(ad);
conn.Open();
ds=new DataSet(); try
{
ad.Fill(ds,"student");
dt=ds.Tables["student"];
moverecord();
}
catch(Exception exp)
{
MessageBox.Show(exp.Message );
}
}
private void moverecord()//绑定数据到TEXTBOX
{
textBox1.Text=dt.Rows[i][0].ToString();
textBox2.Text=dt.Rows[i][1].ToString();
textBox3.Text=dt.Rows[i][2].ToString();
}
//移动到第一条记录
private void button1_Click(object sender, System.EventArgs e)
{
i=0;
moverecord();
}
//移动到最后一条记录
private void button4_Click(object sender, System.EventArgs e)
{
i=dt.Rows.Count-1;
moverecord();
}
//向前移动记录
private void button2_Click(object sender, System.EventArgs e)
{
i--;
if(i<0)
{
i=0;
}
moverecord();
}
//向后移动记录
private void button3_Click(object sender, System.EventArgs e)
{
i++;
if(i>dt.Rows.Count-1)
{
i=dt.Rows.Count-1;
}
moverecord();
}
//添加记录,清空文本框
private void button5_Click(object sender, System.EventArgs e)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox1.Focus();
}
//保存添加的记录
private void button6_Click(object sender, System.EventArgs e)
{
try
{
DataRow dr=dt.NewRow();
dr[0]=this.textBox1.Text;
dr[1]=this.textBox2.Text;
dr[2]=this.textBox3.Text;
dt.Rows.Add(dr);
ad.Update(ds,"student");
ds.AcceptChanges();
}
catch(Exception exp)
{
MessageBox.Show(exp.Message);
}
}
//删除记录
private void button7_Click(object sender, System.EventArgs e)
{ dt.Rows[i].Delete();
ad.Update(ds,"student");
ds.AcceptChanges();
}
//更新记录
private void button8_Click(object sender, System.EventArgs e)
{
dt.Rows[i][0]=textBox1.Text;
dt.Rows[i][1]=textBox2.Text;
dt.Rows[i][2]=textBox3.Text;
ad.Update(ds,"student");
ds.AcceptChanges();
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;namespace WindowsApplication6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private SqlConnection conn;
private SqlDataAdapter ad;
private DataSet ds;
private DataTable dt;
private int i;
private SqlCommandBuilder cmdB;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
conn=new SqlConnection("server=b02;uid=xcj;pwd=xcj;database=pubs");
ad=new SqlDataAdapter("select * from student",conn);
cmdB=new SqlCommandBuilder(ad);
conn.Open();
ds=new DataSet(); try
{
ad.Fill(ds,"student");
dt=ds.Tables["student"];
moverecord();
}
catch(Exception exp)
{
MessageBox.Show(exp.Message );
}
}
private void moverecord()//绑定数据到TEXTBOX
{
textBox1.Text=dt.Rows[i][0].ToString();
textBox2.Text=dt.Rows[i][1].ToString();
textBox3.Text=dt.Rows[i][2].ToString();
}
//移动到第一条记录
private void button1_Click(object sender, System.EventArgs e)
{
i=0;
moverecord();
}
//移动到最后一条记录
private void button4_Click(object sender, System.EventArgs e)
{
i=dt.Rows.Count-1;
moverecord();
}
//向前移动记录
private void button2_Click(object sender, System.EventArgs e)
{
i--;
if(i<0)
{
i=0;
}
moverecord();
}
//向后移动记录
private void button3_Click(object sender, System.EventArgs e)
{
i++;
if(i>dt.Rows.Count-1)
{
i=dt.Rows.Count-1;
}
moverecord();
}
//添加记录,清空文本框
private void button5_Click(object sender, System.EventArgs e)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox1.Focus();
}
//保存添加的记录
private void button6_Click(object sender, System.EventArgs e)
{
try
{
DataRow dr=dt.NewRow();
dr[0]=this.textBox1.Text;
dr[1]=this.textBox2.Text;
dr[2]=this.textBox3.Text;
dt.Rows.Add(dr);
ad.Update(ds,"student");
ds.AcceptChanges();
}
catch(Exception exp)
{
MessageBox.Show(exp.Message);
}
}
//删除记录
private void button7_Click(object sender, System.EventArgs e)
{ dt.Rows[i].Delete();
ad.Update(ds,"student");
ds.AcceptChanges();
}
//更新记录
private void button8_Click(object sender, System.EventArgs e)
{
dt.Rows[i][0]=textBox1.Text;
dt.Rows[i][1]=textBox2.Text;
dt.Rows[i][2]=textBox3.Text;
ad.Update(ds,"student");
ds.AcceptChanges();
}
}
}