从sql server获取数据并插入int asp.net文本框

编程入门 行业动态 更新时间:2024-10-26 14:28:40
本文介绍了从sql server获取数据并插入int asp文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

好吧,使用连接字符串 [ ^ ]您可以连接到数据库。 有关数据通信的更多信息,请点击此处: MSDN:使用ADO.NET访问数据 [ ^ ] Bginginners指导通过C#访问SQL Server [ ^ ]

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文本框

本文发布于:2023-10-12 17:34:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   数据   server   sql   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!