1
using Visual.Web.Developer.2010.Express;
using SQL.Server.Management.Studio.2008.R2;


What I'm ultimately trying to do is update a sql database..
I'm stuck at this step.. I've got my webpage to print the sqldatabase content into a div.. Right now, I'm trying to put some content into a textbox. But whenever I debug, it's throwing me this error. The error I am getting
Stuck at this part, please shine some light on my situation.
Also.. Am I going the right way with this? Is there a more effective method of doing this? Opinions and links to good tutorials/walkthroughs would be appreciated too! Thanks in advance.

My html

<input runat="server" class="hexen" id="investigate1"/><br />
<input type="text" class="hexen" id="investigate2"/><br />
<input type="text" class="hexen" id="investigate3"/><br />
<input type="text" class="hexen" id="investigate4"/><br />
<input type="text" class="hexen" id="investigate5"/><br />
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


My C#

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

namespace WebApplication1
{
    public partial class Default1 : System.Web.UI.Page
    {
        protected void SimpleRead(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=AZUES-336\\JDOESQLSERVER;Initial Catalog=Northwind;Integrated Security=SSPI");
            SqlDataReader rdr = null;

            try
            {

                conn.Open();


                SqlCommand cmd = new SqlCommand("select * from Customers", conn);

                rdr = cmd.ExecuteReader();


                if (rdr.Read())
                {
                    investigate1.Text = rdr.GetValue(0).ToString;//Presumably where the error is happening
                }
            }

            finally
            {
                if (rdr != null)
                { rdr.Close(); }

                if (conn != null)
                { conn.Close(); }
            }
        }
    }
}







@Seany84
Default.aspx

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default1" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<script type="text/javascript">
    $(document).ready(function () {

        $('.hexen').after('<span class="ui-state-default ui-corner-all ui-icon-disk ui-icon saveButton" title="Save" style="float:left"></span>')// ui icon

    .keypress(function () {$(this).next('.saveButton').show();}); //adds ui icon

     $('.ui-state-default').hover(
     function () {$(this).addClass('ui-state-hover');},
     function () {$(this).removeClass('ui-state-hover');}
     ); //ui icon hover

        $('.saveButton').click(function () {
            var id = $(this).prev().attr('id'); //used in the "data" attribute of the ajax call
            var value = $(this).prev().val(); //used in the "data" attribute of the ajax call

            $.ajax({
                type: "POST",
                url: "Default.aspx",
                data: "{Id: " + id + ", Value: " + value + "}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    console.log(data);
                }
            });
            $(this).hide();
        }); //runs ajax call and removes ui-icon after .saveButton is clicked

    }); //end .ready
</script> 

<input runat="server" class="hexen" id="investigate1"/><br />
<input type="text" class="hexen" id="investigate2"/><br />
<input type="text" class="hexen" id="investigate3"/><br />
<input type="text" class="hexen" id="investigate4"/><br />
<input type="text" class="hexen" id="investigate5"/><br />
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>
Johnny Doe
  • 193
  • 2
  • 3
  • 16

2 Answers2

2

You need to use an ASP server control instead of a standard HTML input.

Replace,

<input runat="server" class="hexen" id="investigate1"/>

with

<asp:TextBox ID="investigate1" runat="server" CssClass="hexen" />

and try it then.

Also, should the line:

investigate1.Text = rdr.GetValue(0).ToString;

be this instead:

investigate1.Text = rdr.GetValue(0).ToString();

http://www.asp.net have good tutorials for ASP.net web forms, MVC and web pages.

Seany84
  • 5,526
  • 5
  • 42
  • 67
  • It's throwing me a "parse" error. `The base class includes the field 'investigate1' but it's type is not compatible with the type of control (textbox)` – Johnny Doe Mar 29 '12 at 22:50
  • Are there any other controls in your ASPX with an ID of "investigate1"? Also, can you post your entire ASPX markup please. – Seany84 Mar 29 '12 at 22:51
0

This is the property you have to use:

HtmlInputControl.Value Property

Html Input with runat="server" attribute are converted into HtmlInputControl. And those don't have a Text property, but a Value property. So change Text for Value.

JotaBe
  • 38,030
  • 8
  • 98
  • 117