本文介绍了从asp.net中的storeprocedure获取参数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨有人可以回答我吗?我想向数据库中的存储过程发送一个参数.请帮助我
我写了以下代码:

 字符串 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获取参数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:55