Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2004, 03:27 AM
Authorized User
 
Join Date: Aug 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default urgent ....plz............[:)]

i am doing a project using asp.net and i have created a form that inserts data in to sql database but i have two problems:
1.i need the date text box to have todays date by default and then the user could change it or keep it ,i tried using <asp:textbox id="std" value="<%datetime.now%>"> but didn't work
2.i have adrop down list that contains data from a table in database and i want to save the selected item into another table,i have highlited the code below where i tried to do that.

the code is:

Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
sub Page_Load(Source as Object, E as EventArgs)
dim txtusername as integer
dim group_id as integer
Session("Username") = txtusername
Session("group_id") = group_id
if not Page.IsPostBack then
Dim MySQL as string = "Select [station_id], [station_name] from station where group_id='G5'"
    Dim myConn As SqlConnection = New SqlConnection("data source=ldcTestsrv;database=WaterControl")
    Dim objDR as SQLDataReader
    Dim Cmd as New SQLCommand(MySQL, MyConn)
     MyConn.Open()
    objDR=Cmd.ExecuteReader(system.data.CommandBehavio r.CloseConnection)
    ddlCustomer.DataSource = objDR
    ddlCustomer.DataValueField="station_name"
    ddlCustomer.DataTextField="station_id"
    ddlCustomer.DataBind()
    MyConn.Close()
end if
end sub






Sub doInsert(Source as Object, E as EventArgs)



    Dim MySQL as string = "Insert into generation_station_operation_data (date_stamp,station_id,production,outflow,storage, internal_consumption,total_MGD,production_target,c hange_of_storage_target, change_of_storage) values (@dat,@ddlcustomer,@pro,@out,@sto,@intcon,@tot,@pr odtar,@chstrtr,@chstr)"
    Dim myConn As SqlConnection = New SqlConnection("data source=ldcTestsrv;uid=sa;pwd=;database=WaterContro l")
    Dim Cmd as New SQLCommand(MySQL, MyConn)
    cmd.Parameters.Add(New SQLParameter("@dat", stm.text))
    'cmd.Parameters.Add(New SQLParameter("@sta", stid.text))
    cmd.parameters.add( ddlcustomer.SelectedItem.Value)
    cmd.Parameters.Add(New SQLParameter("@pro", prd.text))
    cmd.Parameters.Add(New SQLParameter("@out", ouf.text))
    cmd.Parameters.Add(New SQLParameter("@sto", sor.text))
    cmd.Parameters.Add(New SQLParameter("@intcon", icons.text))
    cmd.Parameters.Add(New SQLParameter("@tot", MGD.text))
    cmd.Parameters.Add(New SQLParameter("@prodtar", tar.text))
    cmd.Parameters.Add(New SQLParameter("@chstrtr", chtar.text))
    cmd.Parameters.Add(New SQLParameter("@chstr", chstor.text))
     MyConn.Open()
    cmd.ExecuteNonQuery
    label1.visible="true"
    BindData()
    MyConn.Close()
    label1.text = "Your data has been received!"
End Sub

Sub viewthem(Source as Object, E as EventArgs)
mydatagrid.visible="true"
label1.visible="false"
    BindData
End Sub

Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
mydatagrid.visible="true"
    MyDataGrid.CurrentPageIndex = e.NewPageIndex
    BindData
End Sub

Sub BindData()

    Dim MySQL as string = "Select * from generation_station_operation_data order by date_stamp"
    Dim myConn As SqlConnection = New SqlConnection( "data source=ldcTestsrv;uid=sa;pwd=;database=WaterContro l")
    Dim ds as DataSet=New DataSet()
    Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
    Cmd.Fill(ds,"generation_station_operation_data")
    MyDataGrid.Datasource=ds.Tables("generation_statio n_operation_data").DefaultView
    MyDataGrid.DataBind()
End Sub

Sub cleartextboxes(Source as Object, E as EventArgs)
    Dim myForm As Control = Page.FindControl("form1")
    Dim ctl As Control
    For Each ctl In myForm.Controls
        If ctl.GetType().ToString().Equals("System.Web.UI.Web Controls.TextBox") Then
            CType(ctl, TextBox).Text = ""
        End If
    Next ctl
End Sub
</script>
<form id="form1" runat="Server">
    <P><IMG alt="" src="Untitled-43.gif"></P>
    <P align="left"><U><A href="http://localhost/web_test/header.aspx">Home</A>
                    | Log Off</P>
    <STRONG>

    </STRONG></U>
    <P></P>
    <P align="center"><STRONG><U>Generation Station Operation Data</U></STRONG></P>
    <table align="center" border="1">
        <tr>
            <td align="right">
                <P align="left">Date_stamp</P>
            </td>
            <td><asp:textbox id="stm" runat="server"></asp:textbox></td>
        <tr>
         <td align="right">
                <P align="left">Station_id</P>
            </td>
            <td><asp:dropdownlist id="ddlcustomer" runat="server"></asp:dropdownlist></td> <tr>
            <td align="right">
                <P align="left">Production</P>
            </td>
            <td><asp:textbox id="prd" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Outflow</P>
            </td>
            <td><asp:textbox id="ouf" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Storage</P>
            </td>
            <td><asp:textbox id="sor" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Internal_Consumption</P>
            </td>
            <td><asp:textbox id="icons" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Total_MGD</P>
            </td>
            <td><asp:textbox id="MGD" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Production_Target</P>
            </td>
            <td><asp:textbox id="tar" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Change_Of_Storage_Target</P>
            </td>
            <td><asp:textbox id="chtar" runat="server"></asp:textbox></td>
        <tr>
            <td align="right">
                <P align="left">Change_Of_Storage</P>
            </td>
            <td><asp:textbox id="chstor" runat="server"></asp:textbox></td>
        <tr>
        <tr>
            <td align="right" height="22"></td>
            <td height="22"></td>
        <tr>
            <td align="center" colSpan="2">
                <P align="left"><asp:button id="button1" onclick="doInsert" runat="server" Text="Insert"></asp:button><asp:button id="button2" onclick="viewthem" runat="server" Text="view data" causesvalidation="false"></asp:button><asp:button id="button3" onclick="cleartextboxes" runat="server" Text="Clear" causesvalidation="false"></asp:button></P>
            </td>
        </tr>
    </table>


        </asp:datagrid></div>
</form>
<asp:label id="label1" runat="server"></asp:label>



 
Old December 28th, 2004, 07:01 AM
Registered User
 
Join Date: Oct 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Point 1:
<asp:textbox id=std Runat="server">

And in the page_load you write:
 std.Text = New Date().Now



Point 2:
You are trying to get de Selecteditem.value but, dont you need set the property "DatavalueField" of the ddlcustomer dropdownlist?

Hope I help you


 
Old December 29th, 2004, 05:09 AM
Authorized User
 
Join Date: Aug 2004
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx alot for your reply but i have already define it:
 ddlCustomer.DataSource = objDR
    ddlCustomer.DataValueField="station_name"
    ddlCustomer.DataTextField="station_id"
    ddlCustomer.DataBind()

do you know another way to save from drop down list into a database


 
Old January 11th, 2005, 07:27 AM
Registered User
 
Join Date: Oct 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


I do not insert data into DB by the way yo dou do it but it seems you are not setting the value for the parameter "@ddlcustomer"

Do you get some error?





 
Old January 20th, 2005, 01:24 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

noor,

A quick glance at your code (I didn't have time to read all of it) reveiled this:

cmd.parameters.add( ddlcustomer.SelectedItem.Value)

You should try this:

cmd.Parameters.Add(New SQLParameter("@ddlcustomer", ddlcustomer.SelectedItem.Value))


As far as the date problem goes... set it to "today" inside your page_load:

if not Page.IsPostBack then
   stm.Text = DateTime.Now.ToString
   ...
end if

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent ..Plz...Help bluemoon988 ASP.NET 1.0 and 1.1 Basics 0 January 4th, 2008 06:08 AM
URGENT plz do reply maheshoo7 PHP How-To 1 June 26th, 2007 10:20 AM
urgent plz, SachinMalge ASP.NET 2.0 Basics 2 January 16th, 2007 08:37 AM
Very urgent(plz solve) Swati_Jain BOOK: Professional Crystal Reports for VS.NET 2 May 30th, 2006 07:12 AM
Relations (Urgent plz) Samikaraeen Pro VB.NET 2002/2003 0 July 15th, 2004 03:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.