當前位置:首頁 » 數據倉庫 » 資料庫把數據讀出來
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

資料庫把數據讀出來

發布時間: 2022-12-18 08:36:51

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;//返回結果

}
這就讀出來了