运行查询,得到的值,然后更新ASP.net记录(VB) [英] Running a Query, getting a value, then update record in ASP.net (VB)

查看:138
本文介绍了运行查询,得到的值,然后更新ASP.net记录(VB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说实话,我真的想了解这种东西。我一直在使用传统的ASP多年,只是切换到.NET。到目前为止,我并没有太多的乐趣,但我想,我不会放弃。其中一个小片,我挣扎着正在运行的查询,然后,更新记录。即使谷歌搜索的例子,我有一个艰难的时间搞清楚如何做喜欢的事,简单的:

Honest, I am really trying to learn this stuff. I've been using Classic ASP for years and just switching over to .net. So far, I'm not having much fun, but I'm trying and I'm not going to quit. One of the small pieces I am struggling with is running a query then, updating the record. Even googling for examples, I having a tough time figuring out how to do something simple like:


    Set objRS = Server.CreateObject ("ADODB.RecordSet")
ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=G:\Inetpub\wwwroot\TestPage\TheData\TestData.mdb;" & _
          "Persist Security Info=False"

SqlStr = "SELECT * " & _
         "FROM Techs " & _
         "WHERE UserID = " & UserID & " "

objrs.Open SqlStr, ConStr, adOpenStatic, adLockOptimistic,adCmdText
If Objrs.recordCount <> 0 Then
   TechUserName = Objrs("TechUserName")
   Objrs.Update
      Objrs("LastLogin") = Now()
   Objrs.Update
Else
   Objrs.AddNew
      Objrs("UserID") = UserID
   Objrs.Update
End If
Objrs.Close

Set objRS = Nothing

它甚至有可能吗?有人可以帮我做了上述code在ASP.net(VB)或指向我一个很好的彻底教程如何做到这一点。 先谢谢了。

Is it even possible? Can someone please help me do the above code in ASP.net (VB) or point me to a really good thorough tutorial on how to do this. Thanks in advance.

推荐答案

宇豪我知道了!

Dim SqlStr As String
Dim ConStr As String = ConfigurationManager.ConnectionStrings("TCConStr").ConnectionString

SqlStr = "SELECT * " & _
         "FROM TechUsers " & _
         "WHERE TechWWID = " & Chr(34) & TechWWID & Chr(34) & " " & _
         "AND TechEmplNum = " & TechEmplNum & " "

Dim CN As OleDbConnection = New OleDbConnection(ConStr)
CN.Open()
Dim DA As OleDbDataAdapter = New OleDbDataAdapter(SqlStr, CN)
Dim DS As New DataSet
DA.Fill(DS, "TechUsers")
Dim DT As DataTable = DS.Tables("TechUsers")
Dim RecCount As Integer = DT.Rows.Count
Dim CB As OleDbCommandBuilder = New OleDbCommandBuilder(DA)

If RecCount = 0 Then
    DA.InsertCommand = CB.GetInsertCommand()
    Dim DR As DataRow = DT.NewRow()
    DR("TechName") = TechName
    DR("TechWWID") = TechWWID
    DR("TechEmplNum") = TechEmplNum
    DR("FirstLogin") = Date.Now()
    DR("LastLogin") = Date.Now()
    DR("LoginCount") = 1
    DT.Rows.Add(DR)
    DA.Update(DS, "TechUsers")
Else
    Dim DR As DataRow = DT.Rows(0)
    Dim LoginCount As Integer = DR("LoginCount")
    TestStuff.InnerHtml = TestStuff.InnerHtml & "<br > " & LoginCount
    DA.UpdateCommand = CB.GetUpdateCommand()
    DR("LastLogin") = Date.Now()
    DR("LoginCount") = LoginCount + 1
    DA.Update(DS, "TechUsers")
End If

CN.Close()

感谢大家来完成这件事的线索。

Thanks everyone for the clues to get this done.

这篇关于运行查询,得到的值,然后更新ASP.net记录(VB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆