當前位置:首頁 » 操作系統 » winformaccess源碼

winformaccess源碼

發布時間: 2022-08-17 11:04:18

① C#winform程序連接Access資料庫並實現登錄功能,我的代碼不對,請問正確的怎麼寫

兩處錯誤,第一處改為:
strConnection
+=
@"Data
Source=C:\Users\pc533\Desktop\1.mdb";
//
定義連接
第二處改為:
string
sql
=
"select
count(*)
from
user
where
username='"
+
this.textBox1.Text
+
"'
and
password='"
+
this.textBox2.Text
+
"'";

② C# Winform 連接access

private OleDbConnection dataConn()//建立連接
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "資料庫地址" + ";Persist Security Info=False";
OleDbConnection conn = new OleDbConnection(connstr);
return conn;
}

OleDbConnection conn = dataConn();
string sql = "SQL語句";
OleDbCommand myCommand = new OleDbCommand(sql, conn);
conn.Open();//打開表

OleDbDataReader reader = myCommand.ExecuteReader();
while (reader.Read())
MessageBox.Show(reader["欄位"].ToString());//取值

大概是這樣,慢慢理解吧

③ 求c#2010+access 源代碼

已發,個人賬戶管理系統(MoneyManage),那是我做給我自己用的。VS2010+Access03,資料庫在Debug文件夾
打開時候有背景音樂額,可以更換。
還有些地方要改,這算是第一版吧。

④ 在C# winform中使用 richtextbox 向access保存及讀取 圖文混排數據(有源碼,幫忙改一下)

先重載方法,前一個是Sql,後一個是Sql參數集合
插入方法:
public static int ExecuteSql(string SQLString,OleDbParameterCollection parms)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
using (OleDbCommand cmd = new OleDbCommand(SQLString, connection))
{
cmd.Parameters.AddRange(parms);
cmd.ExecuteNonQuery();
}
connection.Close();
}
}
讀取方法:
public object SqlRead(string sqlstring)
{
using (OleDbConnection cn = new OleDbConnection(connectionString))
{
cn.Open();
using (OleDbCommand cmd = new OleDbCommand(sqlstring, cn))
{
object obj=cmd.ExecuteScalar();
if (obj == null)
{
MessageBox.Show("資料庫中目前沒有數據,請先存入!");
}
else
{
return obj;
}
}
cn.Close();
}
}
上面兩個方法呢,寫到你的那個啥類裡面的
調用的時候呢,就
插入:
System.IO.MemoryStream ms = new System.IO.MemoryStream();
this.richTextBox1.SaveFile(ms, RichTextBoxStreamType.RichText);
OleDbParameterCollection param= new OleDbParameterCollection();
param.Add(new OleDbParameter("@rtf",ms));
XX類的.ExecuteSql("insert into [demo] (rtf) values (@rtf)",param);
讀取
byte[] buff=(byte[])XX類的.SqlRead("select top 1 rtf from [demo] order by [id] desc");
System.IO.MemoryStream ms = new System.IO.MemoryStream(btRTF);
rtbDemo.LoadFile(ms, RichTextBoxStreamType.RichText);

其中XX類是你那個啥類

⑤ C#winform程序對access資料庫進行增刪查改操作源碼,叮當小馬的就不用發了

不懂。你這是要OLE得操作方法么?
算了。代碼給出。我這個是SQL得。你改成OLEDB的就能用了。夠詳細吧!
===========================================================
string conn="Server=伺服器名;Database=資料庫名;uid=資料庫用戶名;pwd=資料庫密碼";
SqlConnection sqlconn=new SqlConnection(conn);//連接到資料庫
=========================================================
表的基本操作的語句要SQL的:
添加語句:Insert into 表名 values(欄位名1,欄位名2)
修改語句:Update 表明
set 欄位名1=修改的值,欄位名1=修改的值
where 欄位名=所修改的記錄欄位名
刪除語句:delete 表名 where 欄位名=所要刪除欄位的名稱
查詢語句:select * from 表名
=================================================================
例:
資料庫名為:Test, 資料庫用戶名為:sa , 資料庫密碼:123
有表名為:Admin
該表的欄位:id(int)、name(varchar(8))、pwd(varchar(8))
id name pwd
1 aa 123
2 bb 456
3 cc 789
=========================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
public string sql;
protected void Page_Load(object sender, EventArgs e)
{
sql = "select * from Admin"; //查詢語句
bind(sql);
}
protected void bind(string sql)
{
string conn="Server=.;DataBase=Test;uid=sa;pwd=123";
SqlConnection sqlconn=new SqlConnection(conn);
SqlCommand cmd=new SqlCommand(sql,sqlconn);
sqlconn.Open();
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource=dr;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
sql = "delete Admin where id=" + Convert.ToInt32(TextBox1.Text);//刪除語句
string conn = "Server=.;DataBase=Test;uid=sa;pwd=123";
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand(sql, sqlconn);
sqlconn.Open();
cmd.ExecuteReader();
bind("select * from Admin");
}
protected void Button2_Click(object sender, EventArgs e)
{
sql = "insert into Admin values('" + TextBox2.Text + "','" + TextBox3.Text + "')";//添加語句
string conn = "Server=.;DataBase=Test;uid=sa;pwd=123";
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand(sql, sqlconn);
sqlconn.Open();
cmd.ExecuteReader();
bind("select * from Admin");
}
protected void Button3_Click(object sender, EventArgs e)
{
sql = "update Admin set name='" + TextBox5.Text + "',pwd='" + TextBox6.Text + "' where id=" + Convert.ToInt32(TextBox4.Text);//修改語句
string conn = "Server=.;DataBase=Test;uid=sa;pwd=123";
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand(sql, sqlconn);
sqlconn.Open();
cmd.ExecuteReader();
bind("select * from Admin");
}

⑥ 誰有C#連接access資料庫源碼啊,小弟跪求(2010版access資料庫)。

//C#
publicvoidConnectToAccess()
{
System.Data.OleDb.OleDbConnectionconn=new
System.Data.OleDb.OleDbConnection();
//TODO:
//.
conn.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;"+
@"Datasource=C:DocumentsandSettingsusername"+
@"MyDocumentsAccessFile.mdb";
try
{
conn.Open();
//Insertcodetoprocessdata.
}
catch(Exceptionex)
{
MessageBox.Show("Failedtoconnecttodatasource");
}
finally
{
conn.Close();
}
}

更多參考請訪問以下資源:

http://www.codeproject.com/Articles/8269/How-to-link-to-an-Access-Database-in-a-C-Applicati

http://msdn.microsoft.com/zh-cn/library/cc437979(v=vs.71).aspx

熱點內容
王者榮耀電腦如何改戰區安卓 發布:2025-01-17 13:23:18 瀏覽:814
華為手機如何開啟說出密碼 發布:2025-01-17 13:23:12 瀏覽:101
伺服器在美國說明什麼 發布:2025-01-17 13:14:10 瀏覽:11
啟辰t90有哪些配置 發布:2025-01-17 13:05:40 瀏覽:38
手機微博密碼怎麼改密碼忘了怎麼辦 發布:2025-01-17 13:04:44 瀏覽:959
微笑雲伺服器 發布:2025-01-17 13:03:25 瀏覽:83
android頂部標題欄 發布:2025-01-17 13:02:28 瀏覽:692
androidjs傳遞參數 發布:2025-01-17 12:51:54 瀏覽:477
建築大師輔助腳本 發布:2025-01-17 12:47:33 瀏覽:331
sql向上 發布:2025-01-17 12:43:57 瀏覽:275