I just creates this stored procedure in selecting palletnumber=datatype is int. SerialNumber is varchar. Then pallet numbers are 1 - 200..But if i enter 2 it shows 2 with other palletnumbers. I change @search to nchar and its ok but serialnumber is has error. Im new in stored procedure.
ALTER PROCEDURE [dbo].[sp_SearchFresh]
-- Add the parameters for the stored procedure here
@Search varchar(50)--so that i only have one search engine/input box
AS
SELECt dbo.Monitor.SerialNumber,
WIP.dbo.WIPTEST.PartNumber,
dbo.Monitor.PalletNumber
FROM WIP.dbo.WIPTEST
INNER JOIN dbo.Monitor
ON WIP.dbo.WIPTEST.SerialNumber = dbo.Monitor.SerialNumber
WHERE WIP.dbo.WIPTEST.StatusDescription = 'FG-FRESH'
AND (dbo.Monitor.PalletNumber = @Search
OR dbo.Monitor.SerialNumber LIKE @Search + '%' )
END
it works..i will practice dynamic SQL. But how can i supply null values on my ui? this is my DAL code
public DataSet FGSearch_Grid(Ientity user) {
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("sp_SearchFresh", conn);
cmd.CommandType = CommandType.StoredProcedure;
DataSet dSet = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
cmd.Parameters.Add("@Search", SqlDbType.VarChar, 50).Value = user.Search;
try
{
conn.Open();
da.Fill(dSet, "WIPDATA");
conn.Close();
}
catch (SqlException)
{
throw;
}
return dSet;
}