获取列的值,具体取决于另一列的值

时间:2016-03-20 18:38:48

标签: sql

我想从“条形码”列中获取所有数据(与“名称”列匹配)。像这样:

/* Column widths */
.columnTime{
    width:7%;
}
.columnTheme1Class {
    width: 76%;
}
.columnTheme2Classes {
    width: 64%;
}
.columnTheme3Classes {
    width: 52%;
}
.columnName {
    width: 17%;
}
table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
}
table th, td {
    /* Comment out the following line if you do not want borders */
    border: 1px #d3d3d3 solid;
    /* This is the default font for all cells */
    font-family: Calibri;
}
table tbody tr:hover td {
    color: #000;
    background: #efefef;
}
.cellBibleReading {
    padding-left: 3mm;
    font-size: 11pt;
    font-weight: 700;
    text-transform: uppercase;
}
.cellTime {
    padding-left: 3mm;
    padding-right: 5mm;
    font-size: 9pt;
    font-weight: 700;
    color: gray;
}
.cellName {
    font-size: 10pt;
    font-weight: normal;
}
.floatRight {
    color: gray;
    padding-top: 1mm;
    padding-bottom: 1mm;
    padding-right: 2mm;
    float: right;
    text-align: right;
    font-size: 8pt;
    font-weight: 700;
    text-transform: none;
}
.tableHEADINGOuter {
    border-top-style: none;
    border-left-style: none;
    border-right-style: none;
    border-bottom: 1px gray solid;
    padding-bottom: 2px;
    margin-bottom: 5mm;
}
.tableHEADING {
}
.tableHEADING td {
    vertical-align: bottom;
    border-top-style: none;
    border-left-style: none;
    border-right-style: none;
    border-bottom: 4px gray solid;
}
.tableDATE {
    margin-bottom: 2mm;
}
.tableTFGW {
    margin-bottom: 2mm;
}
.cellTFGW {
    padding-left: 1mm;
}
.textTFGW {
    padding-left: 1mm;
    padding-top: 1mm;
    padding-bottom: 1mm;
    background-color: #606a70;
    width: 90mm;
    font-size: 10pt;
    font-weight: 700;
}
.bulletTFGW {
    padding-top: 1mm;
    padding-bottom: 1mm;
    padding-right: 1mm;
    color: #606a70;
    font-size: 14pt;
    font-weight: normal;
}
.tableAYFM {
    margin-bottom: 2mm;
}
.cellAYFM {
    padding-left: 1mm;
}
.textAYFM {
    padding-left: 1mm;
    padding-top: 1mm;
    padding-bottom: 1mm;
    background-color: #c18626;
    width: 90mm;
    font-size: 10pt;
    font-weight: 700;
}
.bulletAYFM {
    padding-top: 1mm;
    padding-bottom: 1mm;
    padding-right: 1mm;
    color: #c18626;
    font-size: 14pt;
    font-weight: normal;
}
.cellClass {
    font-size: 8pt;
    font-weight: 700;
    vertical-align: bottom;
    color: gray;
}
.tableLAC {
    margin-bottom: 2mm;
}
.cellLAC {
    padding-left: 1mm;
}
.textLAC {
    padding-left: 1mm;
    padding-top: 1mm;
    padding-bottom: 1mm;
    background-color: #961526;
    width: 90mm;
    font-size: 10pt;
    font-weight: 700;
}
.bulletLAC {
    padding-top: 1mm;
    padding-bottom: 1mm;
    padding-right: 1mm;
    color: #961526;
    font-size: 14pt;
    font-weight: normal;
}
.textDuration {
    padding-left: 1mm;
    font-family: Calibri;
    font-size: 9pt;
    font-weight: normal;
}
.textTheme {
    font-size: 11pt;
    font-weight: normal;
}
.textSongLabel {
    font-size: 11pt;
    font-weight: normal;
}
.textSongNumber {
    font-size: 12pt;
    font-weight: normal;
}
.textCongregation {
    text-align: left;
    font-size: 11pt;
    font-weight: 700;
}
.textTitle {
    text-align: right;
    font-size: 18pt;
    font-weight: 700;
}

但这不起作用。

2 个答案:

答案 0 :(得分:0)

如果您的意思是根据选定的类别值获取条形码,则需要将所选值作为SqlParameter传递。恩。在你的OnCategoryChanged函数中,

    string queryString =
        "SELECT barcode FROM table1 where category=@category;";

    using (SqlConnection connection =
               new SqlConnection(connectionString))
    {
        var cmd =  new SqlCommand(queryString, connection);
        cmd.Parameters.AddWithValue("@category", comboBox1.SelectedValue);
        connection.Open();

        var reader = cmd.ExecuteReader();

       ...

        // Call Close when done reading.
        reader.Close();
    }

答案 1 :(得分:0)

如果有人愿意发送,我仍在等待回答。考虑我上面和下面的评论。谢谢......