CREATE PROCEDURE SelectByIdList ( @productIds xml ) AS SET ARITHABORT ON -- @Products table for Products Non-contiguous XML query DECLARE @Products TABLE (ProductID int) INSERT INTO @Products (ProductID) SELECT ParamValues.ProductID.value('.','INT') FROM @productIds.nodes('/Products/ProductID') as ParamValues(ProductID) SELECT * FROM Products INNER JOIN @Products p ON Products.ProductID = p.ProductID -- Test the procedure EXEC SelectByIdList @productIds= '<Products><ProductID>37</ProductID><ProductID>6</ProductID> <ProductID>15</ProductID><ProductID>3</ProductID></Products>' |
private DataTable sp_SelectByIdList(XElement idElements) { using (StringWriter swStringWriter = new StringWriter()) { using (SqlConnection dbConnection = new SqlConnection (MyDataAddin.Properties.Settings.Default.NorthwindConnectionString)) { using (SqlCommand dbCommand = new SqlCommand("SelectByIdList", dbConnection)) { dbCommand.CommandType = CommandType.StoredProcedure; SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@productIds"; parameter.DbType = DbType.Xml; parameter.Direction = ParameterDirection.Input; // Input Parameter parameter.Value = idElements.ToString(); dbCommand.Parameters.Add(parameter); dbConnection.Open(); SqlDataAdapter da = new SqlDataAdapter(dbCommand); northwindDataSet.sp_SelectByIdList.Clear(); da.Fill(this.northwindDataSet.sp_SelectByIdList); return this.northwindDataSet.sp_SelectByIdList; } } } } |
private void selectButton_Click(object sender, EventArgs e) { XElement xmlIdElements = new XElement("Products"); foreach (DataGridViewRow row in vw_ProductListDataGridView.Rows) { if (true == Convert.ToBoolean(row.Cells["SelectCheckbox"].Value)) { xmlIdElements.Add(new XElement("ProductID", Convert.ToInt32(row.Cells["ProductIDColumn"].Value))); } } //Bind the DataGridView sp_SelectByIdListDataGridView.DataSource = sp_SelectByIdList(xmlIdElements); } |
public void BindForm(DataRow currentRow) { access.TextBox textBox; //Fill Form from BindingSource //Set Form Textbox values based on ColumnName match foreach (DataColumn c in currentRow.Table.Columns) { if (ThisDatabase.AllForms["Dashboard"].FindControl(c.ColumnName)) { textBox = ThisDatabase.AllForms["Dashboard"].Controls(c.ColumnName) as access.TextBox; textBox.Value = currentRow[c.ColumnName].ToString(); } } textBox = null; } } } |
int rowPosition = 0; void prevCommand_Click() { if (this.SqlXmlDataGrid != null && this.SqlXmlDataGrid.Visible) { if (rowPosition > 0) { rowPosition--; this.SqlXmlDataGrid.BindForm (this.SqlXmlDataGrid.CurrentDataRow.Table.Rows[rowPosition]); } } } void nextCommand_Click() { if (this.SqlXmlDataGrid != null && this.SqlXmlDataGrid.Visible) { if (rowPosition + 1 < this.SqlXmlDataGrid.CurrentDataRow.Table.Rows.Count) { rowPosition++; this.SqlXmlDataGrid.BindForm (this.SqlXmlDataGrid.CurrentDataRow.Table.Rows[rowPosition]); } } } |


