在表单上加载数据的方法 [英] Method to load data on the form

查看:88
本文介绍了在表单上加载数据的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



我创建了一个Web表单,用于将数据汇总到数据库,它没有任何错误。它显示在griedview上



现在我决定添加一个更新按钮。但我不知道从哪里开始更新satatement。你可以帮我解决一下如何写一个更新声明。



我想知道我是否可以点击griedview中的数据并显示在形式,以便我可以更新,是吗?你能告诉我怎么样吗?



如果我犯了错误,你可以纠正我。



我现在想我已经提供了足够的细节。



谢谢.....







Good Day,

I have created a web form for sumbmiting data to the database and it is working with no errors. It diplays on a griedview

now i have decided to add an update button. but i dont know where to start with my updating satatement. can you please help me on how to write an update statement.

I want to know if it is possible for me to click data in a griedview and it shows on the form so that i can update,is yes? can you please show me how?

You can rectify me if theres mistake i did.

I think now i have provided enough details.

Thanks.....



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;

public partial class Register : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
    
        
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
        conn.Open();
        
        
    }

    protected void btnregister_Click(object sender, EventArgs e)
    {
        SqlCommand comm = new SqlCommand("insert into tblreg values(''"+txtuser.Text+"'',''"+txtPass.Text+"'',''"+txtFulln.Text+"'',''"+txtSurname.Text+"'',''"+txtemail.Text+"'',''"+dropCountry.Text+"'',''"+dropProvince.Text+"'')",conn);
        comm.ExecuteNonQuery();
        GridView1.DataBind();
        txtuser.Text = "";
        txtPass.Text = "";
        txtFulln.Text = "";
        txtSurname.Text = "";
        txtemail.Text = "";
        dropCountry.SelectedItem.ToString();
        dropProvince.SelectedItem.ToString();
        

        //try
        //{
        //    conn.Close();
        //    Response.Redirect("Login.aspx");
        //}
        //catch(Exception ex)
        //{
        //    Response.Write("Error");
        //}
        //finally
        //{
        //    Response.Write("Executed");
        //}
    }

    private void formloaddata()
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
        string strquery = "Select UserID,Username,Password,Fullname,Surname,Email Address,Country,Province";
        SqlDataReader read = new SqlDataReader(conn, strquery);
        GridView1.DataBind();


    }


    protected void btnUpdate_Click(object sender, EventArgs e)
    {
       
        
    }
}

推荐答案

我建​​议你从这里开始: ADO.NET [ ^ ]



那里你会找到ADO.NET的代码示例: http://msdn.microsoft.com/en- us / library / dw70f090.aspx [ ^ ]



来自CP知识库:

为初学者使用ADO.NET [ ^ ]

初学者理解ADO.NET的教程 [ ^ ]
I would suggest you to start here: ADO.NET[^]

There you''ll find code examples for ADO.NET: http://msdn.microsoft.com/en-us/library/dw70f090.aspx[^]

From CP Knowledge Base:
Using ADO.NET for beginners[^]
A Beginner''s Tutorial for Understanding ADO.NET[^]


private void formloaddata()
    {
 SqlDataReader read
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString01"].ConnectionString);
conn.open   //Open your Connection
        string strquery = "Select UserID,Username,Password,Fullname,Surname,Email Address,Country,Province from "Write your TableName"";
        SqlCommand cmd=new SqlCommand(strquery,conn);
        read = cmd.ExecutenonQuery();
if read.hasrows
{
read.Read();
textbox1.text=read("UserID"); // assign this reader to your respective TextBoxes
textbox2.text=read("Username");
textbox3.text=read("Password");
textbox4.text=read("Fullname");
textbox5.text=read("Surname");
textbox6.text=read("Email ");
textbox7.text=read("Address");
textbox8.text=read("Country");
textbox9.text=read("Province");
}     

    }





将代码写入try catch块,这样如果发生错误,我会知道错误是什么



write the code in a try catch block so if error occurs you will come to know what the error is


这篇关于在表单上加载数据的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆