i have one store procedure like :
ALTER procedure [dbo].[prcDisplayTpTestimonial]
@personname varchar(100),
@orderby varchar(100),
@OrderByDirection varchar(100)
As
Begin
set nocount on;
select t.id_testimonials,
(select client_name
from tp_Client_Master c
where c.client_id = t.client_id) as client_name,
t.Person_Name,
t.Description
from tp_Testimonial_master t
where t.Person_name like '%' + @personname + '%'
and t.syncoperation <> 'D'
order by case
when @orderby = 'Person_Name'
and @OrderByDirection = 'asc' then Person_Name
end asc,
case
when @orderby = 'Person_Name'
and @OrderByDirection = 'desc' then Person_Name
end desc,
case
when @orderby = 'Description'
and @OrderByDirection = 'asc' then Description
end asc,
case
when @orderby = 'Description'
and @OrderByDirection = 'desc' then Description
end desc
End
which is work fine but when i run my cs page it give uniqueidentifier error here is my cs code :
SqlCommand cmd1 = new SqlCommand("prcDisplayTpTestim开发者_StackOverflow社区onial", con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("@personname", SqlDbType.VarChar)).Value = clientSearch.Text.ToString().Trim();
cmd1.Parameters.Add(new SqlParameter("@orderby", SqlDbType.VarChar)).Value = sort;
cmd1.Parameters.Add(new SqlParameter("@OrderByDirection", SqlDbType.VarChar)).Value = sort_direction;
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd1);
adp.Fill(dt);
dgTestimonial.DataSource = dt;
dgTestimonial.DataBind();
Somewhere, you're passing a string value to a uniqueidentifier field in your database.
Make sure c.client_id
and t.client_id
are both the same data type.
As far as the data type you choose goes, remember that the uniqueidentifier
type is meant more for things like email addresses in a table so that each row has a unique email address on it (for example) - unless I'm mistaken.
For row ID columns, I use either int
data types with identity(1,1)
on the column, or I use a varchar
data type with a default value of new guid()
.
Hope this helps.
精彩评论