问题描述
嗨有人可以回答我吗?我想向数据库中的存储过程发送一个参数.请帮助我我写了以下代码:
字符串 aname = TextBox1.Text; SqlConnection con = 新 SqlConnection(" 数据源=.初始目录= NezamPezeshki;集成安全性= True"); SqlCommand cmd = 新 SqlCommand(" InsertActionType" ,con); cmd.CommandType = CommandType .StoredProcedure; cmd.Parameters.Add(" @ Aname" ,SqlDbType.VarChar)= aname; SqlDataAdapter ad = 新 SqlDataAdapter(cmd); DataSet ds = 新 DataSet(); con.Open(); int 行= cmd.ExecuteNonQuery(); con .Close(); }
但我收到2错误
错误1分配的左侧必须是变量,属性或索引器C:\ Documents and Settings \ abarsazan.co \ My Documents \ Visual Studio 2005 \ WebSites \ WebSite12 \ Default.aspx.cs 24 9 C:\ ... \ WebSite12 \
错误2无法将类型``string''隐式转换为``System.Data.SqlClient.SqlParameter''C:\ Documents and Settings \ abarsazan.co \ My Documents \ Visual Studio 2005 \ WebSites \ WebSite12 \ Default.aspx.cs 24 59 C:\ ... \ WebSite12 \
hianyone can answer to me ? I want send one parameter to my stored procedure that is in my database.PLEASE HELP ME
i wrote following codes:
string aname = TextBox1.Text; SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=NezamPezeshki;Integrated Security=True"); SqlCommand cmd = new SqlCommand("InsertActionType", con); cmd.CommandType =CommandType .StoredProcedure ; cmd.Parameters.Add("@Aname", SqlDbType.VarChar) = aname ; SqlDataAdapter ad=new SqlDataAdapter (cmd); DataSet ds=new DataSet (); con.Open(); int rows = cmd.ExecuteNonQuery(); con .Close (); }
but i recieve 2 error
Error1The left-hand side of an assignment must be a variable, property or indexerC:\Documents and Settings\abarsazan.co\My Documents\Visual Studio 2005\WebSites\WebSite12\Default.aspx.cs249C:\...\WebSite12\
Error2Cannot implicitly convert type ''string'' to ''System.Data.SqlClient.SqlParameter''C:\Documents and Settings\abarsazan.co\My Documents\Visual Studio 2005\WebSites\WebSite12\Default.aspx.cs2459C:\...\WebSite12\
这篇关于从asp.net中的storeprocedure获取参数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!