이 데이터베이스에 대한 검색 버튼을 만들려고합니다. 내가 여기서 잘못하고있는 것이 확실하지 않습니다. 그것은 나를 준다 오류 System.NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되어 있지 않습니다. 이것은 문자열 constring .. 등등에 관해서입니다. 그것은 그것이 어쨌든 빨간색으로 강조 표시됩니다.asp.net의 액세스 데이터베이스에서 gridview의 검색 버튼이 작동하지 않습니다.
그래서 액세스 문자열 연결에 대한 기사를 읽었습니다. 나는 그것이 말한 것을했다. 나는 내가 뭘 잘못하고 있는지 보지 않고있다.
코드 :
public partial class StudentView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.BindGrid();
}
private void BindGrid()
{
string path = "C:\\Users\\Andrew James Heid\\Desktop\\12\\App_Code\\University DB.accdb";
string conString = ConfigurationManager.ConnectionStrings["Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path].ConnectionString;
string query = "SELECT * FROM Students";
string id = TextBox1.Text.Trim();
if (!string.IsNullOrEmpty(id))
{
id = string.Format(" where ID = '{0}'", id);
}
SqlCommand cmd = new SqlCommand(query + id);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
}
}
어디서 오류가 발생합니까? –
'.ConnectionStrings'은 연결 문자열 이름이나 색인을 필요로합니다. –
@Hanlet 예제가 무엇입니까? –