で初期化されていなかった私は、この問題を解決する助けてください:のConnectionStringプロパティは、ASP.NET
をConnectionStringプロパティが初期化されていません。
私はASP.NETが初めてです。
ログイン後にユーザ名を表示しようとしています(Label1.Text
)。あなたは、2つの異なるインスタンスを持つ
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Botswna_Centralized_Health_Card_System.healthcareOfficerLogins
{
public partial class healthcareOfficerLogins : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["hospital_name"] == null)
{
Response.Redirect("~/hospital_login/hospital_login.aspx");
}
else
{
SqlConnection con = new SqlConnection("Data Source=BOW-PC\\BOW;Initial Catalog= BCHCS;Integrated Security=True");
con.Open();
showdata();
}
}
public void showdata()
{
cmd.CommandText="select * from hospitallogins where hospital_Name='" + Session["hospital_Name"]+ "'";
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(ds);
Label1.Text= ds.Tables[0].Rows[0]["hospital_Name"].ToString();
}
}
}
どのラインでエラーが発生しますか?これがエラーを引き起こすコードであることは確かですか? – Steve
エラーを引き起こす行ではないことを確認してください。 – OctoCode
申し訳ありませんコードを編集しました...私はshowdata()メソッドを追加しました... sda.Fill(ds); –