473,506 Members | 17,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web Calendar to Access Database

I'm trying create a calendar control that updates an access database with
events. I have some code I managed to piece together. First error I'm
running into is the Mycommand.ExecuteNonQuery(). I get an error on this line
as it looks for the query. Here's the first piece of the code where I'm able
to get display calendar and the input boxes. Just trying to write back to
database. Thanks in advance.

Public Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'Add the items to the _Type DropDownList Web Control
_Type.Items.Add(New ListItem("Mailing", "1"))
_Type.Items.Add(New ListItem("House ad", "2"))
_Type.Items.Add(New ListItem("Trade show", "3"))
_Type.Items.Add("Test")

_Date.SelectedDate = _Date.TodaysDate
End If
End Sub
Sub Do_Insert(ByVal Sender As Object, ByVal e As EventArgs)

'Only update the database if the user entered valid inputs
If Not Page.IsValid Then Exit Sub

'Add the event to the database

Dim myConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Inetpub\wwwroot\vacation.MDB")
Dim myCommand As New OleDb.OleDbCommand("Insert into
tbl_Marketing(_Date,Type,Title,Audience,PersonResp onsible)
values(_Date,Type,Title,Audience,PersonResponsible )", myconnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim parameterTitle As New OleDbParameter("@Title",
OleDbType.VarChar, 50)
parameterTitle.Value = Title.Text
myCommand.Parameters.Add(parameterTitle)

'I used the simplest version of the calendar control to allow the
'user to pick the date. So, to retrieve the value from the control,
'I needed to get the value from the SelectedDate property
Dim parameterDate As New OleDbParameter("@_Date", OleDbType.Date, 8)
parameterDate.Value = _Date.SelectedDate
myCommand.Parameters.Add(parameterDate)

Dim parameterAudience As New _
OleDbParameter("@Audience", OleDbType.VarChar, 50)
parameterAudience.Value = Audience.Text
myCommand.Parameters.Add(parameterAudience)

Dim parameterPResponsible As New _
OleDbParameter("@PersonResponsible", OleDbType.VarChar,
50)
parameterPResponsible.Value = PResponsible.Text
myCommand.Parameters.Add(parameterPResponsible)

Dim parameterType As New OleDbParameter("@Type", OleDbType.Integer, 4)
parameterType.Value = _Type.SelectedItem.Value
myCommand.Parameters.Add(parameterType)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

Response.Redirect("default.aspx") 'Redirect the user to the calendar
End Sub
--
Hutty
Nov 19 '05 #1
3 2756
Wow, I see a lot of code that is out of whack here.

Why are you setting myCommand.CommandType = CommandType.StoredProcedure when
you are using a SQL statement, not a stored procedure? By the way, Access
doesn't use stored procedures anyway.
Why are you using Access as your data repsitory for a web page? Access has
limited concurrent user capabilities and will become unstable as you get
past about 10 concurrent connections.
Why are you creating all those parameters and adding them to your command,
but not using them in your INSERT statement?
Why aren't you using Try...Catch to catch your exception(s) and troubleshoot
from there?

It seems like you have pieced together this code from snippets you picked up
here and there, but I would strongly recommend going back and researching
how to create and configure a command object.

-Scott

"Hutty" <Hu***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I'm trying create a calendar control that updates an access database with
events. I have some code I managed to piece together. First error I'm
running into is the Mycommand.ExecuteNonQuery(). I get an error on this
line
as it looks for the query. Here's the first piece of the code where I'm
able
to get display calendar and the input boxes. Just trying to write back to
database. Thanks in advance.

Public Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'Add the items to the _Type DropDownList Web Control
_Type.Items.Add(New ListItem("Mailing", "1"))
_Type.Items.Add(New ListItem("House ad", "2"))
_Type.Items.Add(New ListItem("Trade show", "3"))
_Type.Items.Add("Test")

_Date.SelectedDate = _Date.TodaysDate
End If
End Sub
Sub Do_Insert(ByVal Sender As Object, ByVal e As EventArgs)

'Only update the database if the user entered valid inputs
If Not Page.IsValid Then Exit Sub

'Add the event to the database

Dim myConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Inetpub\wwwroot\vacation.MDB")
Dim myCommand As New OleDb.OleDbCommand("Insert into
tbl_Marketing(_Date,Type,Title,Audience,PersonResp onsible)
values(_Date,Type,Title,Audience,PersonResponsible )", myconnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim parameterTitle As New OleDbParameter("@Title",
OleDbType.VarChar, 50)
parameterTitle.Value = Title.Text
myCommand.Parameters.Add(parameterTitle)

'I used the simplest version of the calendar control to allow the
'user to pick the date. So, to retrieve the value from the control,
'I needed to get the value from the SelectedDate property
Dim parameterDate As New OleDbParameter("@_Date", OleDbType.Date,
8)
parameterDate.Value = _Date.SelectedDate
myCommand.Parameters.Add(parameterDate)

Dim parameterAudience As New _
OleDbParameter("@Audience", OleDbType.VarChar, 50)
parameterAudience.Value = Audience.Text
myCommand.Parameters.Add(parameterAudience)

Dim parameterPResponsible As New _
OleDbParameter("@PersonResponsible", OleDbType.VarChar,
50)
parameterPResponsible.Value = PResponsible.Text
myCommand.Parameters.Add(parameterPResponsible)

Dim parameterType As New OleDbParameter("@Type", OleDbType.Integer,
4)
parameterType.Value = _Type.SelectedItem.Value
myCommand.Parameters.Add(parameterType)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

Response.Redirect("default.aspx") 'Redirect the user to the
calendar
End Sub
--
Hutty

Nov 19 '05 #2
Actually, the code comes from this site
http://aspnet.4guysfromrolla.com/articles/041603-1.aspx

Since I'm not using SQL server I have to use an access database. I would
expect a total of 30 users totally for what i have in mind. I was trying to
substitute oledb where sql was in the code below. In attempt that I could
achieve same results from above website. Any information in obtaining task
at hand is helpful. thanks
"Scott M." wrote:
Wow, I see a lot of code that is out of whack here.

Why are you setting myCommand.CommandType = CommandType.StoredProcedure when
you are using a SQL statement, not a stored procedure? By the way, Access
doesn't use stored procedures anyway.
Why are you using Access as your data repsitory for a web page? Access has
limited concurrent user capabilities and will become unstable as you get
past about 10 concurrent connections.
Why are you creating all those parameters and adding them to your command,
but not using them in your INSERT statement?
Why aren't you using Try...Catch to catch your exception(s) and troubleshoot
from there?

It seems like you have pieced together this code from snippets you picked up
here and there, but I would strongly recommend going back and researching
how to create and configure a command object.

-Scott

"Hutty" <Hu***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I'm trying create a calendar control that updates an access database with
events. I have some code I managed to piece together. First error I'm
running into is the Mycommand.ExecuteNonQuery(). I get an error on this
line
as it looks for the query. Here's the first piece of the code where I'm
able
to get display calendar and the input boxes. Just trying to write back to
database. Thanks in advance.

Public Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'Add the items to the _Type DropDownList Web Control
_Type.Items.Add(New ListItem("Mailing", "1"))
_Type.Items.Add(New ListItem("House ad", "2"))
_Type.Items.Add(New ListItem("Trade show", "3"))
_Type.Items.Add("Test")

_Date.SelectedDate = _Date.TodaysDate
End If
End Sub
Sub Do_Insert(ByVal Sender As Object, ByVal e As EventArgs)

'Only update the database if the user entered valid inputs
If Not Page.IsValid Then Exit Sub

'Add the event to the database

Dim myConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Inetpub\wwwroot\vacation.MDB")
Dim myCommand As New OleDb.OleDbCommand("Insert into
tbl_Marketing(_Date,Type,Title,Audience,PersonResp onsible)
values(_Date,Type,Title,Audience,PersonResponsible )", myconnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim parameterTitle As New OleDbParameter("@Title",
OleDbType.VarChar, 50)
parameterTitle.Value = Title.Text
myCommand.Parameters.Add(parameterTitle)

'I used the simplest version of the calendar control to allow the
'user to pick the date. So, to retrieve the value from the control,
'I needed to get the value from the SelectedDate property
Dim parameterDate As New OleDbParameter("@_Date", OleDbType.Date,
8)
parameterDate.Value = _Date.SelectedDate
myCommand.Parameters.Add(parameterDate)

Dim parameterAudience As New _
OleDbParameter("@Audience", OleDbType.VarChar, 50)
parameterAudience.Value = Audience.Text
myCommand.Parameters.Add(parameterAudience)

Dim parameterPResponsible As New _
OleDbParameter("@PersonResponsible", OleDbType.VarChar,
50)
parameterPResponsible.Value = PResponsible.Text
myCommand.Parameters.Add(parameterPResponsible)

Dim parameterType As New OleDbParameter("@Type", OleDbType.Integer,
4)
parameterType.Value = _Type.SelectedItem.Value
myCommand.Parameters.Add(parameterType)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

Response.Redirect("default.aspx") 'Redirect the user to the
calendar
End Sub
--
Hutty


Nov 19 '05 #3
The code changes you've made make the original code incorrect.

The original code used SQL Server and Stored Procedures. You've substituted
Access (which doesn't use SP's), so you need to change the commandType of
the command to CommandText, or better yet, just remove the line altogether
since text is the default.

You've switched the code from stored procedures to a SQL statement but not
taken advantage of all the parameters created in the code. You should
change your INSERT statement to include these parameters, rather than using
variables.

The opening of the connection and the ExecuteNonQuery should absolutely 100%
be enclosed in a Try...Catch statement with the closing of the connection in
the Finally section. I don't care if the code came form Bill Gates himself,
this is a must.

Lastly (as stated before), you really shouldn't be using Access for this.
You should look into using the MSDE or SQL Server.
"Hutty" <Hu***@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
Actually, the code comes from this site
http://aspnet.4guysfromrolla.com/articles/041603-1.aspx

Since I'm not using SQL server I have to use an access database. I would
expect a total of 30 users totally for what i have in mind. I was trying
to
substitute oledb where sql was in the code below. In attempt that I could
achieve same results from above website. Any information in obtaining
task
at hand is helpful. thanks
"Scott M." wrote:
Wow, I see a lot of code that is out of whack here.

Why are you setting myCommand.CommandType = CommandType.StoredProcedure
when
you are using a SQL statement, not a stored procedure? By the way,
Access
doesn't use stored procedures anyway.
Why are you using Access as your data repsitory for a web page? Access
has
limited concurrent user capabilities and will become unstable as you get
past about 10 concurrent connections.
Why are you creating all those parameters and adding them to your
command,
but not using them in your INSERT statement?
Why aren't you using Try...Catch to catch your exception(s) and
troubleshoot
from there?

It seems like you have pieced together this code from snippets you picked
up
here and there, but I would strongly recommend going back and researching
how to create and configure a command object.

-Scott

"Hutty" <Hu***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
> I'm trying create a calendar control that updates an access database
> with
> events. I have some code I managed to piece together. First error I'm
> running into is the Mycommand.ExecuteNonQuery(). I get an error on
> this
> line
> as it looks for the query. Here's the first piece of the code where
> I'm
> able
> to get display calendar and the input boxes. Just trying to write back
> to
> database. Thanks in advance.
>
> Public Sub Page_Load(ByVal Sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> If Not Page.IsPostBack Then
> 'Add the items to the _Type DropDownList Web Control
> _Type.Items.Add(New ListItem("Mailing", "1"))
> _Type.Items.Add(New ListItem("House ad", "2"))
> _Type.Items.Add(New ListItem("Trade show", "3"))
> _Type.Items.Add("Test")
>
> _Date.SelectedDate = _Date.TodaysDate
> End If
> End Sub
> Sub Do_Insert(ByVal Sender As Object, ByVal e As EventArgs)
>
> 'Only update the database if the user entered valid inputs
> If Not Page.IsValid Then Exit Sub
>
> 'Add the event to the database
>
> Dim myConnection = New System.Data.OleDb.OleDbConnection( _
> "provider=Microsoft.Jet.OLEDB.4.0; " & _
> "data source=C:\Inetpub\wwwroot\vacation.MDB")
> Dim myCommand As New OleDb.OleDbCommand("Insert into
> tbl_Marketing(_Date,Type,Title,Audience,PersonResp onsible)
> values(_Date,Type,Title,Audience,PersonResponsible )", myconnection)
>
> myCommand.CommandType = CommandType.StoredProcedure
>
> Dim parameterTitle As New OleDbParameter("@Title",
> OleDbType.VarChar, 50)
> parameterTitle.Value = Title.Text
> myCommand.Parameters.Add(parameterTitle)
>
> 'I used the simplest version of the calendar control to allow
> the
> 'user to pick the date. So, to retrieve the value from the
> control,
> 'I needed to get the value from the SelectedDate property
> Dim parameterDate As New OleDbParameter("@_Date",
> OleDbType.Date,
> 8)
> parameterDate.Value = _Date.SelectedDate
> myCommand.Parameters.Add(parameterDate)
>
> Dim parameterAudience As New _
> OleDbParameter("@Audience", OleDbType.VarChar, 50)
> parameterAudience.Value = Audience.Text
> myCommand.Parameters.Add(parameterAudience)
>
> Dim parameterPResponsible As New _
> OleDbParameter("@PersonResponsible",
> OleDbType.VarChar,
> 50)
> parameterPResponsible.Value = PResponsible.Text
> myCommand.Parameters.Add(parameterPResponsible)
>
> Dim parameterType As New OleDbParameter("@Type",
> OleDbType.Integer,
> 4)
> parameterType.Value = _Type.SelectedItem.Value
> myCommand.Parameters.Add(parameterType)
>
>
> myConnection.Open()
> myCommand.ExecuteNonQuery()
> myConnection.Close()
>
> Response.Redirect("default.aspx") 'Redirect the user to the
> calendar
> End Sub
> --
> Hutty


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2540
by: Jon | last post by:
Hi All, The company I work for has an Access 97 database on a file server. This was working OK until we upgraded the workstations. The main form for creating a new record has a date box and the...
8
2441
by: Shyguy | last post by:
Is it possible to create a calendar that shows previous input data and also allows for input of new data?
2
2006
by: Smriti Dev | last post by:
Hi There, I want to use the calendar control to pick a date field that is set as date/time in my database. Since space is limited in my form, I would like to make a small little icon that the...
5
4589
by: Miguel Dias Moura | last post by:
Hello, i am trying to create a .css file with several styles and apply them to the calendar control so i can change the look of: 1. Text Type and Format (Bold, Underline, etc) 2. Background...
1
9659
by: afr0ninja | last post by:
Hello all, and thank you in advance for your assistance. I'm pretty new to access and I'm trying to teach myself some VBA by using various bits of code I find here and there mixed with my own....
0
1756
by: jphelan | last post by:
After opening and clicking on the popup calendar command control button, "fdlgCal"; I click on a given date. The date is suppose to then appear in a date field next to the control. Instead, I get...
2
446
by: cdawley4 | last post by:
Hi, I am trying to decide what would be the best program to start a vacation selection calendar in. I am in a group of 60 employees and the current software we have, which I believe is written...
1
2985
by: xian2 | last post by:
Hi, I wanted to create a calendar in Access that would call on data stored within tables in the database (dates in forms) and would show it visually on a calendar when the calendar was opened. I...
3
2704
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.