从数据库中获取数据
您好
如何从 获取
数据库并使用逗号分隔符插入
textbox .Ex:当我点击webform2中的提交时,它会在数据库中插入
data .Webform1想要将该数据显示到文本框中
How to get from database and insert into textbox with comma seperators .Ex:when i click on submit in webform2 it inserts data in database .Webform1 want to display that data into textbox
protected void Page_Load(object sender, EventArgs e)
{
GetServices();
}
public void GetServices()
{
if (!IsPostBack)
{
txt_ServiceSunday.Text = ""; }
else
{
string Connection = System..ConfigurationManager.ConnectionStrings [" Conn"]。ConnectionString;
SqlConnection cn = new SqlConnection(Connection);
cn.Open();
string string1 ="从DetailsTable中选择服务,其中Date = @ Services" ;;
SqlCommand command = new SqlCommand(string1,cn);
command.Parameters.AddWithValue(" @ Services",SqlDbType.DateTime);
command.Parameters [" @ Services"]。Value = lbl_sun.Text;
SqlDataReader dr;
dr = command.ExecuteReader();
if(dr.Read())
{
txt_ServiceSunday.Text = dr [0] .ToString();
txt_ServiceSunday.Text = dr [1] .ToString(); //错误
}
}}
string Connection = System..ConfigurationManager.ConnectionStrings["Conn"].ConnectionString; SqlConnection cn = new SqlConnection(Connection); cn.Open(); string string1 = "select Services from DetailsTable where Date=@Services"; SqlCommand command = new SqlCommand(string1, cn); command.Parameters.AddWithValue("@Services", SqlDbType.DateTime); command.Parameters["@Services"].Value = lbl_sun.Text; SqlDataReader dr; dr = command.ExecuteReader(); if (dr.Read()) { txt_ServiceSunday.Text = dr[0].ToString(); txt_ServiceSunday.Text = dr[1].ToString();//error } } }
如果我新调试它显示了servicessunday.text中的先前值。请提出任何建议吗?
$
If i debug freshly it shows previous value in servicessunday.text .Any suggestions please?
要在webform2中显示数据,您需要从数据库中选择数据并将其放在page_load方法中....
To display the data in webform2 you need to select data from the database and put it in the page_load method....
对于Ex:
protected void Page_Load(object sender,EventArgs e)
  {
$
      if(!IsPostBack)
      {
          SelectData();
$
        }
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SelectData();
}
  }
}
private void SelectData()
private void SelectData()
{
//编写选择查询以选择插入到webform1中的数据
// Write the select Query to select data which is inserted in webform1
当您加载此页面时,您将从webform1获取新插入的数据
when you load this page you will get newly inserted data from webform1
}