从sql server获取数据并插入int asp.net文本框 [英] fetch data from sql server and insert int asp.net textbox

查看:70
本文介绍了从sql server获取数据并插入int asp.net文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从sql server 2008获取数据并将其全部插入到不同的文本框中。请帮助我使用System

解决方案

 
使用System.Configuration;
使用System.Data;
使用System.Linq;
使用System.Web;使用System.Web.Security
;
使用System.Web.UI;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq;
使用System.Data.SqlClient;

public partial class _Default:System.Web.UI.Page
{
SqlConnection con = new SqlConnection(server = Harshit-PC; database = Temp; uid = sa; PWD =印度);
SqlDataReader dr;
SqlCommand cmd;
protected void Page_Load(object sender,EventArgs e)
{
con.Open();

string FetchData =从cus中选择*,其中Name ='fb';
cmd = new SqlCommand(FetchData,con);
dr = cmd.ExecuteReader();

if(dr.Read())
{

TextBox1.Text = dr [0] .ToString();
TextBox2.Text = dr [1] .ToString();
}



}
}





如果不能正常工作,请告诉我!!!


好吧,使用连接字符串 [< a href =http://www.connectionstrings.com/target =_ blanktitle =新窗口> ^ ]您可以连接到数据库。



有关数据通信的更多信息,请点击此处:

MSDN:使用ADO.NET访问数据 [ ^ ]

Bginginners指导通过C#访问SQL Server [ ^ ]


< blockquote> On Search Click



DataTable dt = new DataTable();

// SqlDataAdapter(查询,连接)

SqlDataAdapter adp = new SqlDataAdapter(从TableName中选择*,其中EMPID =+ textBox1.Text +,con);

adp.Fill(dt);

// dt.Ro ws [index] [ColumnName]

textBoxEmpName.text = dt.Rows [0] [Emp_Name]。ToString();



更新时点击





尝试

{

// SqlCommand(查询,连接)

SqlCommand cmd = new SqlCommand(Update tabel TableName set EmpName ='+ textBoxEmpName.Text +'where EMPID =+ textBox1.Text +,con)

;

cmd.ExecuteNonQuery();

}

catch(例外c)

{

}





试试这个


how can i fetch data from sql server 2008 and insert that all into different text box. please help me on this

解决方案

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection("server=Harshit-PC; database=Temp; uid= sa;pwd=india");
    SqlDataReader dr;
    SqlCommand cmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();

        string FetchData = "Select * from cus where Name='fb'";
        cmd = new SqlCommand(FetchData, con);
        dr = cmd.ExecuteReader();

        if (dr.Read())
        {

            TextBox1.Text = dr[0].ToString();
            TextBox2.Text = dr[1].ToString();
        }



    }
}



Please tell me if not working !!!


Well, by using a Connection String[^] you can connect to database.

Further info regarding the data communication can be read here:
MSDN: Accessing data with ADO.NET[^]
Beginners guide to accessing SQL Server through C#[^]


On Search Click

DataTable dt = new DataTable();
//SqlDataAdapter(Query,Connection)
SqlDataAdapter adp = new SqlDataAdapter("Select * from TableName where EMPID="+textBox1.Text+" ",con);
adp.Fill(dt);
// dt.Rows[index][ColumnName]
textBoxEmpName.text = dt.Rows[0]["Emp_Name"].ToString();

On Update Click


try
{
//SqlCommand(query,connection)
SqlCommand cmd = new SqlCommand("Update tabel TableName set EmpName='" + textBoxEmpName.Text + "' where EMPID="+textBox1.Text+"", con)
;
cmd.ExecuteNonQuery();
}
catch(Exception c)
{
}


try this


这篇关于从sql server获取数据并插入int asp.net文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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