winformaccess源码
① 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