2 Replies - 1461 Views - Last Post: 20 December 2012 - 07:37 AM Rate Topic: -----

#1 dhicks19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 18-December 12

Populate datagridview using sql query with a variable

Posted 20 December 2012 - 02:31 AM

Hi, I am having trouble working this out and I am new to programming.

Basically I have a datagridview which is supplied using a dataset.

When editing that dataset in designer you can specify an sql query which is :

 

SELECT [MFNO],[BOARDTYPE] FROM [::this].[mfno] WHERE CUSTCODE = '& CUSTCODE1 &'




I am trying to use the ' & CUSTCODE1 & ' as a variable.
This variable I am hoping will be changed when the a textbox value on the form is changed so it will show only the MFNO for the typed custcode in the text box.

I have declared a variable in form.cs

public class CUSTCODE
{
    public  static string CUSTCODE1 = "PEP001";
}





My textbox on changed code is


string CUSTCODE = textBox1.Text;




I know I am way off but any help will be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Populate datagridview using sql query with a variable

#2 dhicks19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 18-December 12

Re: Populate datagridview using sql query with a variable

Posted 20 December 2012 - 02:39 AM

Basically I am trying to pass the textbox value to the sql query that supplies the datagridview and then requery it to show the results.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5540
  • View blog
  • Posts: 11,868
  • Joined: 02-June 10

Re: Populate datagridview using sql query with a variable

Posted 20 December 2012 - 07:37 AM

Parameterizing Your SQL Queries: The RIGHT Way To Query A Database.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1