本文介绍了如何在文本框的帮助下更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在页面加载期间使用IS NOT NULL查询在数据库的文本框中显示我的数据,点击更新它将在同一行的NAME COLOUMN中分配NNAME coloumn的值,NNAME由NULL分配。

如果NNAME中有更多的行没有空值,那么在每个页面加载事件中它将显示请求,直到NNAME coloumn的所有行都为NULL。我试过这个...有错误....我的aspx.cs:



I want to show my data in textbox from database during page load using IS NOT NULL query and by clicking update it will assign the value of NNAME coloumn in NAME COLOUMN of the same row and NNAME is assign by NULL.
IF there are more rows in NNAME which has not null values then in each page load event it will show the request untill all rows of NNAME coloumn are NULL.I tried till this ...having errors ....MY aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace PROJECT_APPLICATION
{
    public partial class Admin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;
            string query = "SELECT ROLL, REGISTRATION, NAME, NNAME FROM  RESULT_TABLE WHERE NNAME IS NOT NULL ";
            SqlCommand command1 = new SqlCommand(query, con);
            con.Open();
            command1.Parameters.AddWithValue("@NNAME", nname.Text);
            //command1.Parameters.AddWithValue("@REGISTRATION",reg.Text);
            SqlDataReader reader1 = command1.ExecuteReader();


            while (reader1.Read())
            {
                this.roll.Text = (reader1["ROLL"].ToString());
                this.reg.Text = (reader1["REGISTRATION"].ToString());
                this.name.Text = (reader1["NAME"].ToString());
                this.nname.Text = (reader1["NAME"].ToString());
                //this.txtDailyWage.Text = (reader1["DailyWage"].ToString());

                reader1.Close();
            }
        }

        


     protected void Button1_Click1(object sender, EventArgs e)
        {
           string name = nname.Text;
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ConnectionString))


        {
           con.Open();
           using (SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE RESULT_TABLE  SET  NAME = @NNAME   where ROLL  = @ROLL", con))
              {
                 cmd.Parameters.AddWithValue("@NNAME", nname.Text);

                 cmd.Parameters.AddWithValue("@ROLL", roll.Text);
                 cmd.ExecuteNonQuery();
           
          }
        }
      }
    }
}

推荐答案

protected void Page_Load(object sender, EventArgs e)
{
	SqlConnection con = new SqlConnection();
	con.ConnectionString = ConfigurationManager.ConnectionStrings["mycon"].ConnectionString;
	string query = "SELECT ROLL, REGISTRATION, NAME, NNAME FROM  RESULT_TABLE WHERE NNAME IS NOT NULL ";
	SqlCommand command1 = new SqlCommand(query, con);
	con.Open();
	
	//command1.Parameters.AddWithValue("@NNAME", nname.Text);
	//command1.Parameters.AddWithValue("@REGISTRATION",reg.Text);
	SqlDataReader reader1 = command1.ExecuteReader();

	while (reader1.Read())
	{
		this.roll.Text = (reader1["ROLL"].ToString());
		this.reg.Text = (reader1["REGISTRATION"].ToString());
		this.name.Text = (reader1["NAME"].ToString());
		this.nname.Text = (reader1["NAME"].ToString());
		//this.txtDailyWage.Text = (reader1["DailyWage"].ToString());		
	}
	
	reader1.Close();
	con.Close();
}



如果您将获得多条记录,那么它将覆盖您的文本框值。


If you will get multiple records then it will override your textbox value.


这篇关于如何在文本框的帮助下更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 21:02