A. C#如何把数据库里面的东西读出来,并且显示在文本框里面呢
第一步,先建立与数据库的连接
第二步,在program.cs里面写程序
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.sqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaterDal
{
public static class SqliteHelper
{
//从配置文本中读取连接字符串
private static string connStr = "Data Source=数据库的名称;Initial Catalog=SWALL;User ID=SA;Password=666";//是这个数据库没错吧?
public static DataTable GetDataTable(string sql,params SqlParameter[] ps)
{
using (SqlConnection conn=new SqlConnection(connStr))
{
//构造适配器对象
SqlDataAdapter pter=new SqlDataAdapter(sql,conn);
//构造数据表,用于接收查询结果
DataTable dt=new DataTable();
//添加参数
pter.SelectCommand.Parameters.AddRange(ps);
//执行结果
pter.Fill(dt);
//返回结果集
return dt;
}
}
}
}
第三步,在项目里面写程序
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
}
}
}
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
}
}
}
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from lishiji");
dataGridView1.DataSource = Dt;
}
}
}
Form1.cs项目名
private void button4_Click(object sender, EventArgs e)
{
DataTable Dt = SqliteHelper.GetDataTable("select * from jjjj");
dataGridView1.DataSource = Dt;
}
}
}
FROM2.CS项目名
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using CaterDal;
namespace sqlssss
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable Dt = new DataTable();
Dt = SqliteHelper.GetDataTable("select * from lishiji");
DgvQueue.DataSource = Dt;
}
}
}
B. 怎么读取数据库中数据
1、导入.sql文件命令:mysql> USE 数据库名;mysql> source d:/mysql.sql;
2、建立数据库:mysql> CREATE DATABASE 库名;
3、建立数据表:mysql> USE 库名;mysql> CREATE TABLE 表名 (字段名 VARCHAR(20), 字段名 CHAR(1));
4、删除数据库:mysql> DROP DATABASE 库名;
5、删除数据表:mysql> DROP TABLE 表名;
6、将表中记录清空:mysql> DELETE FROM 表名;
7、往表中插入记录:mysql> INSERT INTO 表名 VALUES ("hyq","M");
8、更新表中数据:mysql-> UPDATE 表名 SET 字段名1='a',字段名2='b' WHERE 字段名3='c';
9、用文本方式将数据装入数据表中:mysql> load data local infile "d:/mysql.txt" into table 表名;
C. 想把数据库里一个表的内容读取出来怎么办
打开数据库,点击导出数据,支持多种格式,或者用sql语句
D. 易语言里面怎么把数据库里面的数据读出来 放在编辑框里面
看你的这个界面,你会加入数据么?会的话就比较好办了……具体方法是这样的。
首先要打开数据库。(这里提一下,密码那最好是用文本型,别用整数型)
如果你是要把所有的数据都读出来。就加个循环。
用
计次循环吧。
循环的次数就用
取记录数()
得到的数值。
然后再一个一个的读出来。
读数据直接用
读()
这个命令……
可以用
读(1)
读(2)
也可以用
读("用户名")
读("密码")
上面两种的是一样的……
关于在编辑框里显示出来。用
编辑框.内容=编辑框.内容+读("用户名")+"
"+读("密码")+到文本(#
换行符
)
这样的就OK了……
可能你看得不是很清楚,你自动去试试就知道了。注意看那几个命令的说明。
在循环的最后还要用到个命令
跳过()
这个是从当前数据跳到下一个数据的。
E. 从数据库中读取数据的一般步骤是什么
1、链接数据库2、打开数据库链接3、读取数据记录比如ado的例子: Set Conn = New ADODB.Connection 数据库连接 Set Rec = New ADODB.Recordset 数据库记录
Conn.Open "dsn=pic" 打开数据库链接
Rec.Open "pics", Conn, ad OpenDynamic, adLockOptimistic 读取数据库记录
F. 如何将数据库中得到的数据显示出来
//定义一个函数利用存储过程从数据库中读出数据.当然也可以不用存储过程
public static System.Data.DataRow chaxun1(string Name,string Type)
{
System.Data.SqlClient.SqlConnection cn = new SqlConnection(ConnectionString.Connection.ConnectionString);
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
da.SelectCommand = cmd;
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcere;
cmd.CommandText = "cheng1";
SqlParameter name = new SqlParameter("@名称", SqlDbType.NVarChar);
SqlParameter type = new SqlParameter("@型号", SqlDbType.NVarChar);
name.Value = Name;
cmd.Parameters.Add(name);
type.Value = Type;
cmd.Parameters.Add(type);
DataSet ds = new DataSet();
da.Fill(ds, "MyTable");
DataTable dTable = ds.Tables[0];
DataRow dtRow = dTable.Rows[0];
return dtRow;//返回读取的这一行数据
}
//调用函数,将值赋给要显示它的控件
this.label6.Text = chaxun1(comboBox1.Text,comboBox2.Text)["数量"].ToString();
G. 怎样从数据库中读出数据
public DataSet query(string sql)
{
DataSet ds = new DataSet();//DataSet是表的集合
SqlDataAdapter da = new SqlDataAdapter(sql, conn);//从数据库中查询
da.Fill(ds);//将数据填充到DataSet
connClose();//关闭连接
return ds;//返回结果
}
这就读出来了