<%@dotnet.itags.org. Page Language="VB" Debug="true" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.OleDb" %>
<script runat="server"
dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\admin\Desktop\Reminder\dbReminder.mdb")Sub btnSet_Click(obj as Object, e as EventArgs)
dim objTrans as OleDbTransaction
dim objCmd as OleDbcommand = new OleDbcommand ("INSERT INTO tblReminder (mobile, station, reminder, time) VALUES (@dotnet.itags.org.MOBILE, @dotnet.itags.org.STATION, @dotnet.itags.org.REMINDER, @dotnet.itags.org.TIME)", Conn)
dim objParam as OleDbParameterobjParam = objCmd.Parameters.Add("@dotnet.itags.org.MOBILE", oleDbType.char)
objParam.Direction = ParameterDirection.Input
objParam.Value = lblUser.TextobjParam = objCmd.Parameters.Add("@dotnet.itags.org.STATION", oleDbType.char)
objParam.Direction = ParameterDirection.Input
objParam.Value = lblStation.TextobjParam = objCmd.Parameters.Add("@dotnet.itags.org.REMINDER", oleDbType.Char)
objParam.Direction = ParameterDirection.Input
objParam.Value = DDLFields.SelectedItem.TextobjParam = objCmd.Parameters.Add("@dotnet.itags.org.TIME", oleDbType.char)
objParam.Direction = ParameterDirection.Input
objParam.Value = tbTime.TextConn.Open()
objTrans = Conn.BeginTransaction()
objCmd.Transaction = objTranstry
objCmd.executeNonQuery
objTrans.commit()
catch ex as OleDbException
objTrans.RollBack()
lblError.Text = "Error inserting reminder into database"
end tryobjcmd.Connection.Close()
End subPrivate Sub Page_Load(sender As Object, e As System.EventArgs)
If Not Page.IsPostBack Thendim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\admin\Desktop\Reminder\dbReminder.mdb")
dim objTrans as OleDbTransaction
dim objCmd as OleDbcommand = New OleDbCommand("SELECT time + ' ' + programme as fieldone FROM tblRTE ", Conn)
Conn.Open()DDLFields.DataSource = objCmd.ExecuteReader()
DDLFields.DataTextField = "fieldone"
DDLFields.DataValueField = "fieldone"
DDLFields.DataBind()Conn.Close()
End IfIf Not Request.Cookies("rm_user") Is Nothing Then
lblUser.Text = Request.Cookies("rm_user").Value
end if
End Sub</script>
This is the code im using to take the information from the form and enter it into the database.
But it displays my error message every time...
Is it correct?
The part im not sure about is this:
objParam = objCmd.Parameters.Add("@dotnet.itags.org.REMINDER", oleDbType.Char)
objParam.Direction = ParameterDirection.Input
objParam.Value = DDLFields.SelectedItem.Text
Is this the correct way of taking the selected items text from the ddl?
Thanks.Your code looks good, however your SQL looks dodgy. Thisthread in the DevShed forum should help.
I do somthing similar on a page. I think your problem is that the code for the DDL is in the on postback block. When the page is posted back ( user chose something and clicked button to do save) the ddl is not populated.
Try taking the DDL code out of the is postback IF block...
Private Sub Page_Load(sender As Object, e As System.EventArgs)If Not Page.IsPostBack Then
End Ifdim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\admin\Desktop\Reminder\dbReminder.mdb")
dim objTrans as OleDbTransaction
dim objCmd as OleDbcommand = New OleDbCommand("SELECT time + ' ' + programme as fieldone FROM tblRTE ", Conn)
Conn.Open()
DDLFields.DataSource = objCmd.ExecuteReader()
DDLFields.DataTextField = "fieldone"
DDLFields.DataValueField = "fieldone"
DDLFields.DataBind()
Conn.Close()
If Not Request.Cookies("rm_user") Is Nothing Then
lblUser.Text = Request.Cookies("rm_user").Value
end if
End Sub
also, I don't think you need the transaction stuff. Transactions are used for multiple DB actions. not a single action. The try block should suffice. If the single DB action fails ( your insert) there are no other actions to rollback.
Hope that helps
> I think your problem is that the code for the DDL is in the on postback block. When the
> page is posted back ( user chose something and clicked button to do save) the ddl is not
> populated. Try taking the DDL code out of the is postback IF block...
This is not the problem. The DDL is repopulated via ViewState on PostBack.
I do agree about the Transaction.
One thing that would help solve this is for emmettd to post the error message.
I talking about the error message in my code.
its "Error inserting reminder into database"
its in the code, in the btnSet_click, near the end.
change this line and let us know what you get
lblError.Text =ex.tostring()
0 comments:
Post a Comment