c 程序连接不上mysql数据库连接_asp.net c代码错误(mysql数据库连接)

我有一个密码

我将下拉列表绑定到数据库

后来,

on button click

我连接到

数据库以获取

标签。

我的第一部分工作得很好,但是当我试着做第二部分时,我得到的错误信息是

在System.Data.SqlClient.SqlConnection.OnError(SqlException exception,Boolean breakConnection)在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection,在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)上运行(RunBehavior RunBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,在System.Data.SqlClient.SqlDataReader.consummetadata()在System.Data.SqlClient.SqlDataReader.get_MetaData()在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior RunBehavior,在System.Data.SqlClient.SqlCommand.RunExecuteReaders(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、Boolean async)上,在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法,在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior RunBehavior,Boolean returnStream,String method)在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,String method)在System.Data.SqlClient.SqlCommand.ExecuteReader()在默认值下按1。单击(对象发送方,事件参数e)位于c:\文档和设置\a\My Documents\Visual Studio 2008\WebSites\toolbar1\Default.aspx.cs:第56行

我的代码是:

using System;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

try

{

SqlConnection myConn = new SqlConnection("Server=localhost;Database=testcase;Integrated Security=SSPI");

SqlCommand myCmd = new SqlCommand("select skey,casecode from casetype", myConn);

myConn.Open();

SqlDataReader myReader = myCmd.ExecuteReader();

//Set up the data binding.

DropDownList3.DataSource = myReader;

DropDownList3.DataTextField = "skey";

DropDownList3.DataValueField = "casecode";

DropDownList3.DataBind();

//Close the connection.

//myConn.Close();

//myReader.Close();

//Add the item at the first position.

DropDownList3.Items.Insert(0, "");

}

catch (Exception ex)

{

Response.Write(ex.StackTrace);

}

}

}

protected void Button1_Click(object sender, EventArgs e)

{

try

{

SqlConnection myConn1 = new SqlConnection("Server=localhost;Database=testcase;Integrated Security=SSPI");

SqlCommand myCmd1 = new SqlCommand("select casename,skey from casetype where skey=?", myConn1);

myConn1.Open();

SqlDataReader myReader1 = myCmd1.ExecuteReader();

String type = DropDownList3.SelectedItem.Text;

myCmd1.Parameters.AddWithValue("?", type);

}

catch (Exception exw)

{

Response.Write(exw.StackTrace);

}

}

}

请帮我解决我的问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值