|
hi, i need to write a code to add record into the access database in 3 table. which are actor, director and movie. when the user click the submit button it will add the details into the respective table. i have done the movie table. Now i need to do the actor n director table. for my actor aspx there is a dropdown list for user to select if the user select a actor n click the add button the selected item will be display in the listbox, if the user select others then they need to enter the name in the text box and when the user click the add new the name in the textbox will be added into the listbox. And same for the director then the user click the submit button the record in the lsitbox will be added into the access database in the actor n movie table. below is the code that i have done so far. please advice. thanks in advance.
HTML source
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Add.aspx.vb" Inherits="WebApplicationDvd._Default" %>
<title>Untitled Page
<asp:label id="AddNewDvd" runat="server" designtimedragdrop="8" font-bold="True"
="" font-names="Times New Roman" font-size="14pt" width="240px">Add new DVD Record | | | | <asp:label id="Moviename" runat="server" font-size="14pt" width="112px">DVD Title: | <asp:textbox id="txtmovieName" runat="server"> | <asp:label id="Actor" runat="server" font-size="14pt" width="112px">Actor: | <asp:dropdownlist id="DropDownList1" runat="server" enabletheming="True" width="132px" datasourceid="SqlDataSource1" datatextfield="Actor_Name" datavaluefield="Actor_Name">
<asp:listitem>
<asp:button id="btnAdd" runat="server" text="Add" width="72px">
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:dvd_rentalConnectionString2 %>"
="" providername="<%$ ConnectionStrings:dvd_rentalConnectionString2.ProviderName %>" selectcommand="SELECT [Actor Name] AS Actor_Name FROM [Actor]">
<asp:textbox id="txtActorname" runat="server">
<asp:button id="btnAddNew" runat="server" text="Add New">
<asp:listbox id="lstbxActor" runat="server" height="94px" width="166px">
<asp:button id="btnDelete" runat="server" text="Delete">
| <asp:label id="Director" runat="server" font-size="14pt" width="112px">Director: | <asp:dropdownlist id="DropDownList2" runat="server" width="138px" datasourceid="SqlDataSource2" datatextfield="Director_Name" datavaluefield="Director_Name">
<asp:button id="btnAddD" runat="server" text="Add" width="64px">
<asp:sqldatasource id="SqlDataSource2" runat="server" connectionstring="<%$ ConnectionStrings:dvd_rentalConnectionStringdirector %>"
="" providername="<%$ ConnectionStrings:dvd_rentalConnectionStringdirector.ProviderName %>" selectcommand="SELECT [Director Name] AS Director_Name FROM [Director]">
<asp:textbox id="txtDirector" runat="server">
<asp:button id="btnAddNewD" runat="server" text="Add New">
<asp:listbox id="ListBox2" runat="server" height="102px" width="168px">
<asp:button id="btnDeleteD" runat="server" text="Delete">
| <asp:label id="language" runat="server" font-size="14pt" width="112px">Language: | <asp:textbox id="txtlanguage" runat="server"> | <asp:label id="Numberofdisc" runat="server" font-size="14pt" width="145px">Number of Disc: | <asp:textbox id="txtNoofDisc" runat="server"> | <asp:label id="Studio" runat="server" font-size="14pt" width="112px">Studio: | <asp:textbox id="txtStudio" runat="server"> | <asp:label id="ReleaseDate" runat="server" font-size="14pt" width="112px">Release Date: | <asp:textbox id="txtReleaseDate" runat="server"> | <asp:label id="Price" runat="server" font-size="14pt" width="112px">Price: | <asp:textbox id="txtPrice" runat="server"> | <asp:label id="Quantity" runat="server" font-size="14pt" width="112px">Quantity: | <asp:textbox id="txtQuantity" runat="server"> | | | <asp:button id="btnSubmit" runat="server" text="Submit"> | |
<asp:calendar id="Calendar1" runat="server">
VB code
Partial Public Class _Default
Inherits System.Web.UI.Page
'Public atMydropdownlist As DropDownList
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim Moviename
Dim Actorname
Dim Director
Dim Language
Dim Numberofdisc
Dim Studio
Dim ReleaseDate
Dim Price
Dim Quantity
Dim sql
'Dim asql
Dim DBconn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("dvd_rental.mdb"))
DBconn.Open()
Moviename = Request.Form("txtmovieName")
Actorname = Request.Form("txtActorname")
Director = Request.Form("txtDirector")
Language = Request.Form("txtLanguage")
Numberofdisc = Request.Form("txtNoofdisc")
Studio = Request.Form("txtStudio")
ReleaseDate = Request.Form("txtReleaseDate")
Price = Request.Form("txtPrice")
Quantity = Request.Form("txtQuantity")
sql = "INSERT INTO Movie(MovieName, MovieLanguage, Numberofdisc, Studio, ReleaseDate, Price, Quantity) "
sql = sql & "VALUES('" & Moviename & "'"
sql = sql & ",'" & Language & "'"
sql = sql & ",'" & Numberofdisc & "'"
sql = sql & ",'" & Studio & "'"
sql = sql & ",'" & ReleaseDate & "'"
sql = sql & ",'" & Price & "'"
sql = sql & ",'" & Quantity & "')"
Dim dbquery As New OleDb.OleDbCommand
dbquery.CommandType = CommandType.Text
dbquery.CommandText = sql
dbquery.Connection = DBconn
dbquery.ExecuteNonQuery()
DBconn.Close()
DBconn = Nothing
Response.Redirect("Webdvd.aspx")
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
'Dim DBconn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("dvd_rental.mdb"))
DropDownList1.DataValueField = "Others"
End Sub
Protected Sub txtActorname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtActorname.TextChanged
End Sub
Protected Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If DropDownList1.SelectedValue <> "Others" Then
lstbxActor.Text = DropDownList1.SelectedValue
ElseIf DropDownList1.SelectedValue = "Others" Then
txtActorname.Focus()
End If
End Sub
End Class
|
|
|
|
|
ling_luv wrote: Moviename = Request.Form("txtmovieName")
Why do you do your insert in the page load ? What if someone refreshes the page ? Why use the Form and not txtmovieName.Text ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi, thanks for ur help, i did nt write abny code in the page load. i have change the txtmoviename which u have written. thanks. but how abt the actor n director? please advice. thanks
|
|
|
|
|
Yeah, I missed a line, sorry.
I'm not sure what you're asking. You have code for an insert, why do you have trouble with inserting some values into a different table ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi i did try the same code but it like not able to work. Now the problem is in the dropdownlist of actor when the actor click add then the selected value need to be in the listbox, if the value is "Others" then they user will need to enter the name n when they click add new the name will go to the listbox now i have problem in adding the value into the listbox. please advice on how to add the value into the listbox when the user click add n add new. Thanks
|
|
|
|
|
Your listbox should be populated from a database call, just make a DB call to get the right list of values, set that return value to be the datasource of the control, and call databind
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi. thanks. The requirement that i need to do is to get the value from the dropdownlist n textbox to display in the lsitbox n when the user click the submit button it will add teh value from the lsitbox into the actor n director table in access database. thanks
|
|
|
|
|
You need to get the values that are in the dropdownlist, or you need to use the value in the dropdownlistto work out how to populate the listbox ? Your dropdownlist should give you the info you need to request the correct data for the listbox, that's kind of where I was headed.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
the dropdown list is already [opulated with values. when the user select the item in the dropdownlist n click the add button next to the dropdownlist. the selecteditem need to be disply in the listbox. thankss
|
|
|
|
|
Oh - you want to add one item to the listbox ? This will probably be done in javascript, just handle the button click, grab the selected text from the drop down and add it to the collection of items in the list box. THere's tons of examples on the web for that sort of stuff.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I try to find but not able to find a code that can work any website to recommand? N how do i list the field in Movie Table in GRidView using sql? thanks
|
|
|
|
|
|
|
hi i found the way to add the item into the listbox already. but now i have 1 problem which is if i need to add a few item from teh dropdownlist, it is nt able to because it onlu able to add 1 item only. please advice. thanks
|
|
|
|
|
|
I have the following Stored procedure. There is column named
"tcktreceived" in my database and I want to pass all the rows one by
one to the parameter @starttime. I don't know how to do it.
CREATE PROCEDURE [twcsan].[usp_DateDiff]
-- Add the parameters for the stored procedure here
@starttime DateTime
AS
BEGIN
DECLARE @Diff Varchar(15)
DECLARE @Day INT
DECLARE @Hour INT
DECLARE @Minute INT
DECLARE @Start_Date DateTime
DECLARE @End_Date DateTime
DECLARE @itemReceived DateTime
DECLARE @ID INT
DECLARE @message VARCHAR(50)
DECLARE @table TABLE
(
ItemReceived DateTime,
ID INT,
message text,
Differnce VARCHAR(20)
)
SET NOCOUNT ON;
SET @Start_Date = @starttime
SET @End_Date = GETDATE()
SET @Day = DATEDIFF( day, @Start_Date, @End_Date)
SET @Hour = DATEDIFF(hour , @Start_Date, @End_Date)
SET @Minute = DATEDIFF(minute , @Start_Date, @End_Date)
SET @Minute = @Minute-(@HOUR* 60)
SET @Hour = @Hour-(24* @Day)
SET @Diff = CONVERT(Varchar, @Day) +'d ' + CONVERT(Varchar , @Hour) +
'h ' + CONVERT(Varchar , @Minute) +'m'
INSERT INTO @table(ItemReceived, ID, message, Differnce)
select tck.tcktreceived, tck.ticketid,tckmsg.tcktmessage,@Diff
from tbtickets tck inner join tbticketsmessages tckmsg
on tck.ticketid = tckmsg.ticketid
select * from @table
END
seema
|
|
|
|
|
This is a SQL question, it has nothing to do with ASP.NET, I recommend asking in the SQL forum.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi my fellow this question belongs to sql forums so i recommed you to ask this in sql forums to take an answer quickly and easiyl
Best Greetings
|
|
|
|
|
Please post your Question in the Correct Forum.
Regards,
Satips.
|
|
|
|
|
I have this error when testing my aspx page on intranet.
Server Error in '/smartproject' Application.
-----------------------------------------------------------------------------
Login failed for user 'DIGITAL-NB\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'DIGITAL-NB\ASPNET'.
Source Error:
Line 22: oCnn = New SqlConnection(strConn)
Line 23: If oCnn.State = ConnectionState.Closed Then
Line 24: oCnn.Open()
Line 25: End If
Line 26:
Source File: C:\WebSites\SmartProject\App_Code\SmartPTier.vb Line: 24
I assigned the user ASPNET to Administrator group, and the thing worked.
1. What is the implication of this?
2. Is there any other way to solve this problem without assigning the ASPNET user to Administrator?
3. What is the function of the user ASPNET?
thank u for your response
t.aransiola
|
|
|
|
|
1) Any user and applicaiton running in the ASP.NET process has complete control of your database and server.
2) Grant the ASPNET account access to the specific database necessary or create a sql login account for that database and use it in the connection string. Not using Integrated Security of course.
3) To run ASP.NET
only two letters away from being an asset
|
|
|
|
|
Hi,
I have a table which has a field ItemsReceived of type datetime. I
have a grid view which has two columns.
In first column i have to show the data from field ItemsReceived and
in second column I have to show
difference between Currenttime and date from ItemReceived. How can I
do that.
e'g
ItemRecieved Difference
6/13/2007 12:38am 1d 21h 45m
6/13/2007 3:54pm 1d 06h 10m
6/15/2007 12:26pm 34m
So the second coulmn displays the difference of current time minus
ItemRecieved. the format shouild be <mintues>m,
or<hours>h, <mintues>m, or <days>d.
How can I do that.
seema
|
|
|
|
|
|
i'm using vs 2003 to develop an web app.
it exports data to a excell worksheet and fills some charts.
what is bugging me is that i can't select a chart, fill it and then select another chart and fill it.
in asp i use this
iExcel.Sheets("Graficos").ChartObjects("Gráfico 1025").Activate<br />
Set crt = iExcel.Sheets("Graficos").ChartObjects("Gráfico 1025")<br />
to select the chart and then work with it.
and in asp.net???
how can i do this???
help would be appreciated
thanks in advance
|
|
|
|
|
In ASP.NET it will work exactly the same, as in both cases, you're just using a COM object.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|