2011年11月27日 星期日

#VB Login OO實作學習


'修改登入連線字串,設定在app.config之中

'對config檔案做加密動作

'

====================================================

Visual Basic - Login/登入/登錄之物件導向實作

http://blog.kkbruce.net/2011/09/visual-basic-login.html



寫一個介面,可以隨時更換連線資料庫方式
oledb,odbc,SQL
希望做到只需在前端呼叫使用
後端不需要動到程式碼


'可能需要做到 Transection
 確認成功才送出
否則 roll back

SqlTransaction
http://my.so-net.net.tw/idealist/CS/Basic/transaction.html

SqlTransaction transaction = conn.BeginTransaction();

try
{
 SqlCommand users = new SqlCommand("insert into Users(userid, pwd) 
             values('" + userid + "', '" + pwd + "')", conn);
        users.Transaction = transaction;
        users.ExecuteNonQuery();

        SqlCommand friends = new SqlCommand("insert into friends(userid, friendid) 
            values('" + userid + "', '" + friend1 + "')", conn);
        friends.Transaction = transaction;
        friends.ExecuteNonQuery();

        transaction.Commit();
}
catch
{
        transaction.Rollback();
}
dataAdapter.Update(dataSet)是否有像BeginTransaction()功能

http://social.msdn.microsoft.com/Forums/zh-TW/233/thread/c477b140-1cab-4fb0-8bea-032a15430ae9

SqlBulkCopy 在交易中進行

  Dim transaction As SqlTransaction = _
         connection.BeginTransaction()
        Dim bulkCopy As SqlBulkCopy = New SqlBulkCopy( _
         connection, _
         SqlBulkCopyOptions.KeepIdentity, _
         transaction)
        bulkCopy.BatchSize = 10
        bulkCopy.DestinationTableName = "dbo.BulkCopyDemoMatchingColumns"

        ' Write from the source to the destination.
        Try
            bulkCopy.WriteToServer(reader)
            transaction.Commit()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            transaction.Rollback()
        End Try
        bulkCopy.Close()

沒有留言:

張貼留言