Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Notes
Inherits System.Web.UI.Page
Dim m_Myconnection As SqlConnection
Dim m_MyCommand As SqlDataAdapter
Protected Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
' connect to sql and check for notes for this user
Dim dsn As String = ConfigurationManager.AppSettings("LocalSqlServer")
Dim DS As New DataSet
m_Myconnection = New SqlConnection(dsn)
m_MyCommand = New SqlDataAdapter("select note from notes where username='" & User.Identity.Name & "'", m_Myconnection)
m_MyCommand.Fill(DS, "note")
For Each dr As DataRow In DS.Tables(0).Rows
TextBox1.Text += Convert.ToString(dr("note"))
Next
End Sub
Protected Sub SaveButton_Click(ByVal Source As Object, ByVal e As EventArgs)
'save notes for this user
Dim DS, newset As New DataSet
Dim found As Boolean
Dim nRow As DataRow
For Each masterRow As DataRow In DS.Tables("notes").Rows()
If masterRow("username") = User.Identity.Name Then
masterRow("note") = TextBox1.Text
found = True
End If
Next
If found = False Then
nrow = DS.Tables("notes").NewRow()
nRow("username") = User.Identity.Name
nRow("note") = TextBox1.Text
DS.Tables("notes").Rows.Add(nRow)
End If
newset = DS.GetChanges(DataRowState.Modified)
m_MyCommand.Update(newset, "notes")
End Sub
End Class