Click here to Skip to main content
15,891,423 members
Home / Discussions / C#
   

C#

 
GeneralRe: "This command is not available because no document is open." Pin
Tejas Shastri23-Oct-14 0:54
Tejas Shastri23-Oct-14 0:54 
GeneralRe: "This command is not available because no document is open." Pin
Pete O'Hanlon23-Oct-14 2:28
mvePete O'Hanlon23-Oct-14 2:28 
GeneralRe: "This command is not available because no document is open." Pin
Tejas Shastri23-Oct-14 2:33
Tejas Shastri23-Oct-14 2:33 
GeneralRe: "This command is not available because no document is open." Pin
Pete O'Hanlon23-Oct-14 2:40
mvePete O'Hanlon23-Oct-14 2:40 
GeneralRe: "This command is not available because no document is open." Pin
Tejas Shastri23-Oct-14 4:08
Tejas Shastri23-Oct-14 4:08 
GeneralRe: "This command is not available because no document is open." Pin
Freak3023-Oct-14 3:56
Freak3023-Oct-14 3:56 
GeneralRe: "This command is not available because no document is open." Pin
Tejas Shastri23-Oct-14 4:09
Tejas Shastri23-Oct-14 4:09 
Questionlaunch another Application from memory by C# Pin
iscreen22-Oct-14 0:15
iscreen22-Oct-14 0:15 
AnswerRe: launch another Application from memory by C# Pin
Richard MacCutchan22-Oct-14 0:20
mveRichard MacCutchan22-Oct-14 0:20 
AnswerRe: launch another Application from memory by C# PinPopular
Richard Deeming22-Oct-14 2:45
mveRichard Deeming22-Oct-14 2:45 
GeneralRe: launch another Application from memory by C# Pin
iscreen22-Oct-14 2:57
iscreen22-Oct-14 2:57 
QuestionCalendar Extender Pin
sadmoh21-Oct-14 23:52
sadmoh21-Oct-14 23:52 
Questionusing a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
BillWoodruff21-Oct-14 13:03
professionalBillWoodruff21-Oct-14 13:03 
AnswerRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
Richard Deeming22-Oct-14 2:41
mveRichard Deeming22-Oct-14 2:41 
GeneralRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
BillWoodruff22-Oct-14 6:19
professionalBillWoodruff22-Oct-14 6:19 
GeneralRe: using a Func with dynamic parameters as a query: pros ? cons ? and a few other miscellaneous questions on Func Pin
Richard Deeming22-Oct-14 6:38
mveRichard Deeming22-Oct-14 6:38 
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 

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.