Xtragridview - Where with variable

Asked

Viewed 20 times

0

Everybody good night, how are you?

I’m creating a user registration screen, where every user has an ID, on this screen, I have an xtragridview, which carries some address information.

However, in this xtragridview table, it has addresses of several other customers, so it only needed to bring the addresses of that customer.

I’m trying to create a query, in the gridview datasource:

select "Cliente_enderecos_alter"."id_cliente_cobranca",
   "Cliente_enderecos_alter"."endereco",
   "Cliente_enderecos_alter"."numero",
   "Cliente_enderecos_alter"."bairro",
   "Cliente_enderecos_alter"."cidade",
   "Cliente_enderecos_alter"."estado",
   "Cliente_enderecos_alter"."cep"
from "dbo"."Cliente_enderecos_alter" "Cliente_enderecos_alter"

where  "Cliente_enderecos_alter"."id_cliente" = @id_cliente

Here comes my doubt, as I define this parameter @id_cliente?

If it were a normal consultation, I would do so:

 consql._sql = @"SELECT * FROM Login WHERE id_usu = @id_usu";
 SqlCommand cmd = new SqlCommand(consql._sql, sqlconn);
 cmd.Parameters.Add("@id_usu", SqlDbType.Int).Value = id_usu;
 sqlconn.Open();

But in gridview? how do I???

Valeuu

1 answer

0

Good morning, you guys. After 1 day and a few hours, looking for a solution, I managed to accomplish as follows:

In Sqldatasource, a parameter named "queryParameter1" is created, follows code:

 this.sqlDataSource1.ConnectionName = "String tpspoazsql01 onee";
        this.sqlDataSource1.Name = "sqlDataSource1";
        columnExpression1.ColumnName = "id_cliente_cobranca";
        table1.MetaSerializable = "0|0|125|240";
        table1.Name = "Cliente_enderecos_alter";
        columnExpression1.Table = table1;
        column1.Expression = columnExpression1;
        columnExpression2.ColumnName = "endereco";
        columnExpression2.Table = table1;
        column2.Expression = columnExpression2;
        columnExpression3.ColumnName = "numero";
        columnExpression3.Table = table1;
        column3.Expression = columnExpression3;
        columnExpression4.ColumnName = "bairro";
        columnExpression4.Table = table1;
        column4.Expression = columnExpression4;
        columnExpression5.ColumnName = "cidade";
        columnExpression5.Table = table1;
        column5.Expression = columnExpression5;
        columnExpression6.ColumnName = "estado";
        columnExpression6.Table = table1;
        column6.Expression = columnExpression6;
        columnExpression7.ColumnName = "cep";
        columnExpression7.Table = table1;
        column7.Expression = columnExpression7;
        selectQuery1.Columns.Add(column1);
        selectQuery1.Columns.Add(column2);
        selectQuery1.Columns.Add(column3);
        selectQuery1.Columns.Add(column4);
        selectQuery1.Columns.Add(column5);
        selectQuery1.Columns.Add(column6);
        selectQuery1.Columns.Add(column7);
        selectQuery1.FilterString = "[Cliente_enderecos_alter.id_cliente] = ?id";
        selectQuery1.Name = "Cliente_enderecos_alter";
        queryParameter1.Name = "id";
        queryParameter1.Type = typeof(int);
        queryParameter1.Value = id_cliente;
        selectQuery1.Parameters.Add(queryParameter1);

        selectQuery1.Tables.Add(table1);
        this.sqlDataSource1.Queries.AddRange(new DevExpress.DataAccess.Sql.SqlQuery[] {
        selectQuery1});
        this.sqlDataSource1.ResultSchemaSerializable = resources.GetString("sqlDataSource1.ResultSchemaSerializable");

well, done this, we have to assign a value to our variable "id_client" before the initialization of the form components:

 public Manutenção_cliente(int id)
    {
        this.StartPosition = FormStartPosition.CenterScreen;
        id_cliente = id;

        InitializeComponent();

        // This line of code is generated by Data Source Configuration Wizard
        // Fill a SqlDataSource
        sqlDataSource1.Fill();
    }

With this, I was able to perform the consultation, I do not know if it is the most correct method, if anyone can comment.

Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.