

总提示:“SqlParameterCollection 仅接受非空的 SqlParameter 类型对象,不接受 String 对象。”
SqlConnection conn = new SqlConnection(Log_in.ljmc);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "hanzi";
SqlParameter sqlpar = new SqlParameter("@myhz", SqlDbType.VarChar,50);
sqlpar.Direction = System.Data.ParameterDirection.Input;
sqlpar.Value = "中华人民共和国";
cmd.Parameters.Add("@myhz");
SqlParameter sqlpar1 = new SqlParameter("@daima", SqlDbType.VarChar, 50);
sqlpar1.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add("@daima");
this.textBox1.Text = cmd.Parameters["@daima"].Value.ToString();
conn.Close();
cmd.Dispose();
}
[此贴子已经被作者于2006-8-24 13:51:53编辑过]
一个参数的add方法不能是string,只能是sqlpara值,要给string值,可以
cmd.Parameters.Add("@myhz",SqlDbType.VarChar);