编程论坛's Archiver

terry8675 发表于 2008-7-10 17:14

新手求助!!

static string strconn = "data soruce=localhost\\SQLEXPRESS;initial catalog=gustbook;user id=sa;Password=sa123";
    SqlConnection conn = new SqlConnection(strconn);
为什么老说"System.Data.SqlClient.SqlConnection"并不包含"CreatedCommand"的定义

cyyu_ryh 发表于 2008-7-10 18:10

用System.Data.SqlClient

terry8675 发表于 2008-7-10 18:16

回复 2# cyyu_ryh 的帖子

用了,还是出现这样的错误

terry8675 发表于 2008-7-10 18:44

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

public partial class _Default : System.Web.UI.Page
{
    string strconn = "data source=localhost://SQLEXPRESS;initial catalog=Northwind;user id=sa;password=sa123";
    SqlConnection myconn = new SqlConnection(strconn);

    protected void Page_Load(object sender, EventArgs e)
    {
      
        string strSQL = "select top 5 CategoryID,CategoryName,Description from Categories";
        SqlCommand mycomm = new SqlCommand(strSQL, myconn);
        myconn.open();
        mygv.DataSource = myCommand.ExecuteReader();
        mygv.DataBind();
        myconn.close();
    }
}
又显示不包含open 和  close的定义
各位大虾帮帮忙

ghl2312 发表于 2008-7-11 08:56

myconn.open();
myconn.close();
你觉的这个对吗,C#一定要注意大小写。
应该是:
myconn.Open();
myconn.Close();
刚学的时候记得不要Copy.

ghl2312 发表于 2008-7-11 09:00

回复 4# terry8675 的帖子

SqlConnection myconn = new SqlConnection(strconn);
这一句也要写在PageLoad里面,你的问题可能就出在这。

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.