编译错误
using System;using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string username=TextBox1.Text.Trim();
string mySelectQuery="select top 10 username,value from pay.dbo.sitepoint";
string myConnectsring="userid=test;password=aaa;database=pay;server=aaa-5ffb53b4342";
SqlConnection myConnection = new SqlConnection(mySelectQuery);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
myConnection.Open();
SqlDataReader myDataReader;
myCommand.Execute(out myDataReader);
while (myDataReader.Read())
{
Console.WriteLine(myDataReader.GetInt32(0));
}
myDataReader.Close();
myConnection.Close();
}
}
编译时提示: myCommand.Execute(out myDataReader);
c:\Inetpub\wwwroot\test2\Default.aspx.cs(30,19): error CS0117: “System.Data.SqlClient.SqlCommand”并不包含“Execute”的定义
--------------------编程问答-------------------- myCommand.ExecuteNonQuery(out myDataReader); --------------------编程问答-------------------- myDataReader = cmd.ExecuteNonQuery();
ExecuteNonQuery是不带参数的. --------------------编程问答-------------------- 方法用错了吧
用这个把
SqlDataReader myDataReader=cmd.ExecuteReader()
--------------------编程问答-------------------- enterprise用多了。。。
补充:.NET技术 , ASP.NET