重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
VS+access数据库的,MSSQL数据库的话你改下,反正就2种链接方式,书上都有。
成都创新互联公司是一家专注于成都网站制作、成都做网站与策划设计,兴山网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:兴山等地区。兴山做网站价格咨询:028-86922220
下面是代码和解释,另外我会把文件发到你邮箱里的,你把文件复制到自己的站点文件夹里面运行就可以看到效果了。
Imports System.Data.OleDb
Imports System.Data
Partial Class baidu
Inherits System.Web.UI.Page
'下面是添加记录
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'定义“连接数据库”和“执行SQL”变量
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String
dbname = Server.MapPath("baidu.mdb")
myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" dbname)
myConnection.Open()
'INSERT INTO "表格名" ("栏位1", "栏位2", ...) VALUES ("值1", "值2", ...)
'这里可以加上 昵称 是否已经存在的判断语句,就是 SELECT "栏位名" FROM "表格名" WHERE "条件"
myCommand = New OleDbCommand("Insert INTO a1(昵称) Values('" TextBox1.Text "')", myConnection)
myCommand.ExecuteNonQuery()
Response.AddHeader("Refresh", "0")
'关闭连接()
myConnection.Close()
'释放资源
myCommand.Dispose()
End Sub
'下面是删除记录
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
'定义“连接数据库”和“执行SQL”变量
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String
dbname = Server.MapPath("baidu.mdb")
myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" dbname)
myConnection.Open()
'DELETE FROM "表格名" WHERE {条件}
myCommand = New OleDbCommand("DELETE FROM a1 WHERE 昵称 = '" TextBox1.Text "'", myConnection)
myCommand.ExecuteNonQuery()
Response.AddHeader("Refresh", "0")
'关闭连接()
myConnection.Close()
'释放资源
myCommand.Dispose()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'定义“连接数据库”和“执行SQL”变量
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String
dbname = Server.MapPath("baidu.mdb")
myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" dbname)
myConnection.Open()
myCommand = New OleDbCommand("select * FROM a1", myConnection)
GridView1.DataSource = myCommand.ExecuteReader()
GridView1.DataBind()
'关闭连接()
myConnection.Close()
'释放资源
myCommand.Dispose()
End Sub
End Class
邮件已经发生,请查收。记得给分哈
你选中一条数据的时候把这条数据的ID也给取出来、点击修改把你去到的ID跟页面上三个TEXT框中的值同时转到后台进行修改、删除也是把你选中这行的ID传到SQL里
引用 Microsoft ActiveX Data Objects 2.8 Library
或者加入microsoft ado data control
定义数据库连接
Dim Cnn As New ADODB.Connection
定义操作记录
Dim Res As New ADODB.Recordset
开始使用
If Res.State = 1 Then Res.Close
Res.CursorLocation = adUseClient
Res.Open "SELECT * From 发票表", Cnn, adOpenDynamic, adLockReadOnly
删除用res.Delete
添加用res.AddNew
res.Fields("序号") = Trim(Res.Fields("序号"))
...
res.Update
更新用Res.Update "序号", 111
列:
'写入产品信息
Sub WriteFP()
'On Error Resume Next
Dim SyBaseRes As New ADODB.Recordset
PB.value = 0
Res.Open "SELECT Count(*) From ICSaleEntry INNER JOIN t_Item ON ICSaleEntry.FItemID = t_Item.FItemID INNER JOIN t_MeasureUnit ON ICSaleEntry.FUnitID = t_MeasureUnit.FMeasureUnitID", SQLServer, adOpenDynamic, adLockReadOnly
Text2.Text = "当前共 " Val(Res.Fields(0)) "条数据"
PB.Max = Val(Res.Fields(0))
If Res.State = 1 Then Res.Close
Res.Open "SELECT ICSaleEntry.FDetailID AS 序号,ICSaleEntry.FInterID AS 物料编号, t_Item.FName AS 产品名称,ICSaleEntry.FAuxPrice AS 单价, ICSaleEntry.FAuxQty AS 数量,ICSaleEntry.FAmount AS 原币, ICSaleEntry.FStdAmount AS 本币,t_MeasureUnit.FName AS 单位 FROM ICSaleEntry INNER JOIN t_Item ON ICSaleEntry.FItemID = t_Item.FItemID INNER JOIN t_MeasureUnit ON ICSaleEntry.FUnitID = t_MeasureUnit.FMeasureUnitID", SQLServer, adOpenDynamic, adLockReadOnly
Do While Not Res.EOF
If SyBaseRes.State = 1 Then SyBaseRes.Close
SyBaseRes.Open "select * from 物料表 where 序号='" Res.Fields("序号") "'", Cnn, adOpenDynamic, adLockOptimistic
If SyBaseRes.EOF Then
Text2.Text = Text2.Text + vbCrLf + "正在添加: " Trim(Res.Fields("序号"))
SyBaseRes.AddNew
SyBaseRes.Fields("序号") = Trim(Res.Fields("序号"))
SyBaseRes.Fields("产品编号") = Trim(Res.Fields("物料编号"))
SyBaseRes.Fields("产品名称") = Trim(Res.Fields("产品名称"))
SyBaseRes.Fields("单价") = Trim(Res.Fields("单价"))
SyBaseRes.Fields("数量") = Trim(Res.Fields("数量"))
SyBaseRes.Fields("原币") = Trim(Res.Fields("原币"))
SyBaseRes.Fields("本币") = Trim(Res.Fields("本币"))
SyBaseRes.Fields("单位") = Trim(Res.Fields("单位"))
SyBaseRes.Fields("数据库名") = Trim(Text1.Text)
SyBaseRes.Update
Else
Text2.Text = Text2.Text + vbCrLf + "正在更新: " Trim(Res.Fields("序号"))
SyBaseRes.Update "序号", Trim(Res.Fields("序号"))
SyBaseRes.Update "产品编号", Trim(Res.Fields("物料编号"))
SyBaseRes.Update "产品名称", Trim(Res.Fields("产品名称"))
SyBaseRes.Update "单价", Trim(Res.Fields("单价"))
SyBaseRes.Update "数量", Trim(Res.Fields("数量"))
SyBaseRes.Update "原币", Trim(Res.Fields("原币"))
SyBaseRes.Update "本币", Trim(Res.Fields("本币"))
SyBaseRes.Update "单位", Trim(Res.Fields("单位"))
SyBaseRes.Update "数据库名", Trim(Text1.Text)
End If
PB.value = PB.value + 1
Res.MoveNext
DoEvents
Loop
If SyBaseRes.State = 1 Then SyBaseRes.Close
Set SyBaseRes = Nothing
End Sub
网络希望不要用ACCESS用ASA(就是sybase那个太强了)
sQueryString是SQL(增删查改)语句
public
Boolean
ExecSQL(string
sQueryString)
{
SqlConnection
con
=
new
SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlCommand
dbCommand
=
new
SqlCommand(sQueryString,
con);
try
{
dbCommand.ExecuteNonQuery();
con.Close();
}
catch
{
con.Close();
return
false;
}
return
true;
}
}
建立一个类,明自己取,然后调用就是了
例如:
类
BC=NEW
类();
STRING
ist="INSERT
INTO
XX(1,2,3)VALUES(A,B,C)";
BC.ExecSQL(ist);
就可以了
一般是将access数据库绑定到datagridview中,要添加数据只需要datagridview1.Item(3, 0).Value=XXX这种就行了,删除修改同理。保存到access是你已经有了一个access表吧?不然字段都要新建的。如果要保存到数据库的话就调用sql语句链接数据库了,我找个以前的代码 Dim OleDbConn As OleDbConnection = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=保存信息\保存信息.mdb;persist security info=false")
OleDbConn.Open()
Dim adapter As New OleDbCommand("insert into 受检单位信息(检测日期,测量器具) values(#" + DateTimePicker1.Value + "#,'" + 测量器具 + "')", OleDbConn)
adapter.ExecuteNonQuery()