Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sql更新文本框不显示数据库信息_C#_Sql_Web Application Design - Fatal编程技术网

C# Sql更新文本框不显示数据库信息

C# Sql更新文本框不显示数据库信息,c#,sql,web-application-design,C#,Sql,Web Application Design,我最终要做的是更新sql数据库。 我被困在这一步。。我已将我的网页打印到一个div中。。现在,我正试图把一些内容放到一个文本框中。但每当我调试时,它都会给我这个错误卡在这一部分,请说明我的情况。 也。。我这样做对吗?有没有更有效的方法?如果您有好的教程/演练的意见和链接,也将不胜感激!提前感谢。 我的html using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; @Seany84


我最终要做的是更新sql数据库。
我被困在这一步。。我已将我的网页打印到一个div中。。现在,我正试图把一些内容放到一个文本框中。但每当我调试时,它都会给我这个错误
卡在这一部分,请说明我的情况。
也。。我这样做对吗?有没有更有效的方法?如果您有好的教程/演练的意见和链接,也将不胜感激!提前感谢。

我的html

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







@Seany84
Default.aspx

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(); }
            }
        }
    }
}

$(文档).ready(函数(){
$('.hexen')。在('')//用户界面图标之后
.keypress(函数(){$(this).next('.saveButton').show();});//添加ui图标
$('.ui状态默认值')。悬停(
函数(){$(this.addClass('ui-state-hover');},
函数(){$(this.removeClass('ui-state-hover');}
);//用户界面图标悬停
$('.saveButton')。单击(函数(){
var id=$(this.prev().attr('id');//在ajax调用的“data”属性中使用
var value=$(this.prev().val();//在ajax调用的“data”属性中使用
$.ajax({
类型:“POST”,
url:“Default.aspx”,
数据:“{Id:+Id+”,值:“+Value+”}”,
数据类型:“json”,
contentType:“应用程序/json;字符集=utf-8”,
成功:功能(数据){
控制台日志(数据);
}
});
$(this.hide();
});//在单击保存按钮后运行ajax调用并删除ui图标
}); //结束,准备好了吗






您需要使用ASP服务器控件,而不是标准的HTML输入

取代

<%@ 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>
请改为:

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

提供有关ASP.net web窗体、MVC和网页的良好教程。

这是您必须使用的属性:


带有runat=“server”属性的Html输入被转换为HtmlInputControl。它们没有文本属性,而是值属性。因此,将文本更改为值。

这会给我带来一个“解析”错误
基类包含字段“investigate1”,但其类型与控件类型(文本框)不兼容。
您的ASPX中是否有ID为“investigate1”的其他控件?另外,你能发布你的整个ASPX标记吗?这是一个ASP.net:Web表单还是网页项目?我想是Web表单。。C#ASP.NET WEB应用程序能否发布整个ASPX页面(编辑原始帖子)?好的,这里没有什么想法了。。我刚刚注意到您有一行代码:investigate1.Text=rdr.GetValue(0).ToString;不应该是:investigate1.Text=rdr.GetValue(0.ToString();或者那是一个打字错误?+1代表鹰是的。。干得好,Seany84,这是我的问题。愚蠢的小标记。。谢谢你,伙计,谢谢你的指导
<input runat="server" class="hexen" id="investigate1"/>
<asp:TextBox ID="investigate1" runat="server" CssClass="hexen" />
investigate1.Text = rdr.GetValue(0).ToString;
investigate1.Text = rdr.GetValue(0).ToString();