Click here to Skip to main content
15,885,366 members
Home / Discussions / C#
   

C#

 
GeneralRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
BillWoodruff22-Oct-14 7:44
professionalBillWoodruff22-Oct-14 7:44 
Questionspeedtest.net Like result Pin
Jassim Rahma21-Oct-14 10:21
Jassim Rahma21-Oct-14 10:21 
AnswerRe: speedtest.net Like result Pin
Pete O'Hanlon21-Oct-14 10:26
mvePete O'Hanlon21-Oct-14 10:26 
GeneralRe: speedtest.net Like result Pin
Jassim Rahma21-Oct-14 10:31
Jassim Rahma21-Oct-14 10:31 
GeneralRe: speedtest.net Like result Pin
PIEBALDconsult21-Oct-14 10:35
mvePIEBALDconsult21-Oct-14 10:35 
GeneralRe: speedtest.net Like result Pin
Bernhard Hiller22-Oct-14 22:52
Bernhard Hiller22-Oct-14 22:52 
GeneralRe: speedtest.net Like result Pin
PIEBALDconsult21-Oct-14 10:31
mvePIEBALDconsult21-Oct-14 10:31 
Questiontrying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Sam 910021-Oct-14 8:34
Sam 910021-Oct-14 8:34 
//I have c# code in my form. Search button makes sql conn where I use stored proc to add params.
C#
private void btnSearch_Click(object sender, EventArgs e){
            
            string connectionString = "Data Source="" I verified correct conn String, it works ";
            string  commandText = "sp_Case_Search";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand(commandText, conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandTimeout = 600;
                
                conn.Open();
 cmd.Parameters.Add(new SqlParameter("@Field", SqlDbType.VarChar));

                cmd.Parameters.Add(new SqlParameter("@Field", SqlDbType.VarChar, 50));
                cmd.Parameters.Add(new SqlParameter("@Search", SqlDbType.VarChar, 500));
                
                //add input parameter from stored proc and set value
                
                /*DateTime edtPicker = Convert.ToDateTime(EnterdateDateTimePicker.Value);
                DateTime udtPicker = Convert.ToDateTime(UpdateDateDateTimePicker.Value);
                
                cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Bigint));
                cmd.Parameters.Add(new SqlParameter("@EnterDate", SqlDbType.DateTime)).Value = edtPicker;
                cmd.Parameters.Add(new SqlParameter("@EnterTime", SqlDbType.VarChar)).Value = EnterTimeTextBox.Text;
                cmd.Parameters.Add(new SqlParameter("@EnterBy", SqlDbType.VarChar)).Value = EnterByTextBox.Text;
                cmd.Parameters.Add(new SqlParameter("@CaseTypeID", SqlDbType.Int));
                cmd.Parameters.Add(new SqlParameter("@MethodTypeID", SqlDbType.Int));
                cmd.Parameters.Add(new SqlParameter("@UpdateDate", SqlDbType.DateTime)).Value = udtPicker;
                cmd.Parameters.Add(new SqlParameter("@UpdateBy", SqlDbType.VarChar)).Value = UpdateByTextBox.Text;
                cmd.Parameters.Add(new SqlParameter("@CaseDocNumber", SqlDbType.VarChar)).Value = CaseDocNumberRichTextBox.Text;
                cmd.Parameters.Add(new SqlParameter("@SenderAddress", SqlDbType.VarChar)).Value = senderAddressRichTextBox.Text; */
                
                cmd.ExecuteNonQuery();
                
                cmd.Parameters.Clear();
                conn.Close();

            }


//The WHERE CASE @Field are radio buttons in the form where if one RB is selected populate the SELECT fields in a datarepeater. The commented out is what I tried, produces diff. errors.

SQL
ALTER PROCEDURE [dbo].[sp_Case_Search] 
	-- Add the parameters for the stored procedure here
@Field varchar(50),
@Search varchar(500)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
    declare @Criteria varchar(502) = '%'+ @Search + '%'
	SELECT 
	   [ID]
      ,[EnterDate]
      ,[EnterTime]
      ,[EnterBy]
      ,[CaseTypeID]
      ,[MethodTypeID]
      ,[UpdateDate]
      ,[UpdateBy]
      ,[CaseDocNumber]
      ,[SenderAddress]
            
    FROM  tblNewCaseEntry
        
    WHERE 
    CASE 
    When @Field = 'ServedBy' then ServedBy 
    When @Field = 'CaseDocNumber' then CaseDocNumber 
    When @Field = 'SenderAddress' then SenderAddress
    When @Field = 'Claim' then Claim 
    End like @Criteria
    ORDER BY EnterDate DESC;
END

PLEASE help to use @Field correctly in my code.
Maybe I am doing it ALL WRONG. Thank yoU!
AnswerRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Richard Deeming21-Oct-14 8:47
mveRichard Deeming21-Oct-14 8:47 
AnswerRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
PIEBALDconsult21-Oct-14 9:10
mvePIEBALDconsult21-Oct-14 9:10 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Sam 910021-Oct-14 9:53
Sam 910021-Oct-14 9:53 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
PIEBALDconsult21-Oct-14 10:04
mvePIEBALDconsult21-Oct-14 10:04 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
Sam 910021-Oct-14 11:38
Sam 910021-Oct-14 11:38 
GeneralRe: trying to use stored proc @fields in winforms with sql connection. Error procedure or function @Field expects parameter... Pin
PIEBALDconsult21-Oct-14 11:48
mvePIEBALDconsult21-Oct-14 11:48 
Answerproblem with multicolumncombo and bindingnavigator movenext ,... Pin
fatemehsoleimani21-Oct-14 4:58
fatemehsoleimani21-Oct-14 4:58 
AnswerRe: problem with multicolumncombo and bindingnavigator movenext ,... Pin
fatemehsoleimani21-Oct-14 21:43
fatemehsoleimani21-Oct-14 21:43 
QuestionHow to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
vinod chattergee21-Oct-14 1:06
vinod chattergee21-Oct-14 1:06 
AnswerRe: How to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
Eddy Vluggen21-Oct-14 6:10
professionalEddy Vluggen21-Oct-14 6:10 
GeneralRe: How to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
vinod chattergee23-Oct-14 19:18
vinod chattergee23-Oct-14 19:18 
GeneralRe: How to trigger coded UI tests from C# code or can I draft mstest commands and trigger through process.start? Pin
Eddy Vluggen24-Oct-14 1:35
professionalEddy Vluggen24-Oct-14 1:35 
QuestionImplementing SSO using SAML, C# Pin
shank07ct21-Oct-14 1:05
shank07ct21-Oct-14 1:05 
AnswerRe: Implementing SSO using SAML, C# Pin
OriginalGriff21-Oct-14 2:35
mveOriginalGriff21-Oct-14 2:35 
AnswerRe: Implementing SSO using SAML, C# Pin
Richard MacCutchan21-Oct-14 2:47
mveRichard MacCutchan21-Oct-14 2:47 
QuestionC# assign ProcessID Pin
Alaric_20-Oct-14 10:56
professionalAlaric_20-Oct-14 10:56 
AnswerRe: C# assign ProcessID Pin
Ravi Bhavnani20-Oct-14 11:33
professionalRavi Bhavnani20-Oct-14 11:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.