C# .NET - numericupdown value from database

Asked By Trisha
10-Feb-12 03:26 AM
i want to take numeric up down control value from id column of access database. How to write code for that ????
  kalpana aparnathi replied to Trisha
10-Feb-12 03:36 AM
hi,

Use below code for your solution

RowCount = DataTable row Count

for(int i=0 ; i < RowCount ; i++)
{
     NumericUpDown nupDynCtrl = new NumericUpDown ();

     // This makes your Id unique

     nupDynCtrl.ID = "NumericUpDown" + "i";
    
 }

When you want to retrieve values from Control u can use Controls and type Cast it to NumericUpdown


for(int i=0 ;i < RowCount ; i++)

{
       NumericUpDown nupDynCtrlNew  = (NumericUpdown) this.Controls["NumericUpDown" + "i"]
}

Hope it helps!!!

Thanks,
  Web Star replied to Trisha
10-Feb-12 03:39 AM
See here is complete sample with source code how can use numeric up downs in window form in c#.net
http://www.codeproject.com/Articles/30899/Extended-NumericUpDown-Control 
  Web Star replied to Trisha
10-Feb-12 03:40 AM
Also this is another good sample for that
http://www.dotnetperls.com/numericupdown 
  Somesh Yadav replied to Trisha
10-Feb-12 03:49 AM
Hi Trisha,

Programs sometimes need a control that allows the user to select a number by clicking on an up or down arrow. The Windows Forms platform offers the NumericUpDown control, which features a textbox with a number and also two scroll buttons to change the value. This article describes and uses the NumericUpDown control.

NumericUpDown

Get started

To get started, please add a NumericUpDown control to your Windows Forms program in the Visual Studio designer by double-clicking on the entry in the Toolbox. Next, you can change some properties of the NumericUpDown by right-clicking on it and selecting Properties; these options are described in the latter sections. In this code example, we added the ValueChanged event handler by double-clicking on the NumericUpDown control.


so here is the code For numeric dropdown and value changed.

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
	public Form1()
	{
	    InitializeComponent();
	}

	private void numericUpDown1_ValueChanged(object sender, EventArgs e)
	{
	    // You can change other program parts when the value changes.
	    this.Text = "Value changed to " + numericUpDown1.Value.ToString();
	}
    }
}

For more refer to the below link:-

http://www.dotnetperls.com/numericupdown

Hope this will help you.
  dipa ahuja replied to Trisha
10-Feb-12 04:03 AM
public ComboBind()
    {
          
      string conn = "Connectiostring";
 
      OleDbDataAdapter da = new OleDbDataAdapter("Select * from emp", conn);
      DataSet ds = new DataSet();
      da.Fill(ds);
      comboBox1.DataSource = ds.Tables[0];
      comboBox1.DisplayMember = "empid";
      comboBox1.ValueMember = "empid";
 
 
    }
 

  Sreekumar P replied to Trisha
10-Feb-12 05:40 AM
Hi,

I hope u can get a DatTable from Access database.

den u can use this code (self tested).

DataTable dtNumberUpDownValues = null;
    private void Form1_Load(object sender, EventArgs e)
    {
      BindDropDown();
    }
    bool isFIrst = false;
    private void BindDropDown()
    {
      isFIrst = true;
      //Some how get the Data from DB - it should be ordered (sorted).
      dtNumberUpDownValues = getValues();
      if (dtNumberUpDownValues.Rows.Count > 0)
      {
        //zero th row contains the smallest value
        numericUpDown1.Minimum = Convert.ToDecimal(dtNumberUpDownValues.Rows[0]["NumberValue"]);
        //last th row contains the max value
        numericUpDown1.Maximum = Convert.ToDecimal(dtNumberUpDownValues.Rows[dtNumberUpDownValues.Rows.Count - 1]["NumberValue"]);
 
      }
      oldValue = numericUpDown1.Value;
    }
 
    private DataTable getValues()
    {
      DataTable dt = new DataTable();
      dt.Columns.Add(new DataColumn("NumberValue", typeof(decimal)));
      DataRow dr = dt.NewRow();
      dr["NumberValue"] = 10;
      dt.Rows.Add(dr);
 
      dr = dt.NewRow();
      dr["NumberValue"] = 22;
      dt.Rows.Add(dr);
 
      dr = dt.NewRow();
      dr["NumberValue"] = 33;
      dt.Rows.Add(dr);
 
      dr = dt.NewRow();
      dr["NumberValue"] = 47;
      dt.Rows.Add(dr);
 
      dr = dt.NewRow();
      dr["NumberValue"] = 660;
      dt.Rows.Add(dr);
 
      dr = dt.NewRow();
      dr["NumberValue"] = 1100;
      dt.Rows.Add(dr);
      return dt;
    }
    decimal oldValue = 0;
    bool isOnceChanged = false;
    private void numericUpDown1_ValueChanged(object sender, EventArgs e)
    {
      if (isFIrst)
      {
        isFIrst = false;
        return;
      }
      if (isOnceChanged)
        return;
      if (dtNumberUpDownValues != null)
      {
        if (oldValue < numericUpDown1.Value)
        {
          DataRow[] drs = dtNumberUpDownValues.Select("NumberValue > " + numericUpDown1.Value);
          if (drs.Length > 0)
          {
            isOnceChanged = true;
            numericUpDown1.Value = Convert.ToDecimal(drs[0]["NumberValue"]);
          }
        }
        else
        {
          DataRow[] drs = dtNumberUpDownValues.Select("NumberValue < " + numericUpDown1.Value);
          if (drs.Length > 0)
          {
            isOnceChanged = true;
            numericUpDown1.Value = Convert.ToDecimal(drs[drs.Length - 1]["NumberValue"]);
          }
        }
      }
      oldValue = numericUpDown1.Value;
    }
 
    private void numericUpDown1_Click(object sender, EventArgs e)
    {
      isOnceChanged = false;
    }
Create New Account
help
How to add Checkbox to Colum Header of gridview ( using datatable and datacolumn concept) hi i am creating a datatable and adding datacolumns and datarows to the table and then binding the table to the for one column i need column name to be a checkbox control i am using DataColumn dc9 = new DataColumn ( "" , typeof ( bool )); but here it is taking only the string name so i want the checkbox control , Code DataTable dt = new DataTable (); DataColumn dc1 = new DataColumn ( "Exchange" ); dt.Columns.Add(dc1); DataColumn dc3 = new DataColumn ( "Product Type" ); dt
insert data into SQL 2005 from a text file that I parse. I build a DataTable: [CODE] public DataTable tbl = new DataTable(); public DataTable buildType4DataTable() { DataColumn loadTransactionCode = new DataColumn(); loadTransactionCode.ColumnName = "loadTransactionCode"; tbl.Columns.Add(loadTransactionCode); DataColumn companyID = new DataColumn(); companyID.ColumnName = "companyID"; tbl.Columns.Add(companyID); DataColumn cardholderIdentification = new DataColumn(); cardholderIdentification.ColumnName = "cardholderIdentification"; tbl
Comparing Data Rows hi, public DataTable A() { DataTable DataTableA = new DataTable(); DataColumn myDataColumn; myDataColumn = new DataColumn(); myDataColumn.DataType = Type.GetType("System.String"); myDataColumn.ColumnName = "Field1"; myDataTableB.Columns.Add(myDataColumn); myDataColumn = new DataColumn(); myDataColumn.DataType = Type.GetType("System.String"); myDataColumn.ColumnName = "Field2"; myDataTableB.Columns.Add(myDataColumn); myDataColumn = new DataColumn(); myDataColumn.DataType = Type.GetType("System.String"); myDataColumn.ColumnName = "Field3"; myDataTableB.Columns.Add(myDataColumn); myDataTableB.Rows myDataTableB.Rows.Add(" 7 ", " 13 ", " ColumnB "); myDataTableB.Rows.Add("174", "14", "ColumnA"); return DataTableA ; } public DataTable B() { DataTable myDataTableB = new DataTable(); dt.Columns.Add("ColumnA", typeof(string)); dt.Columns.Add("ColumnB
to create dynamic datatable with 5 columns & 3 rows need to create dynamic datatable with 5 columns & 3 rows hi From the namespace System.Data DataTable DataColumn classes we can easily create table dynamically in C# and also in ASP.NET. using System.Data; / / Create a DataTable instance DataTable dTbl = new DataTable( "myDynamicTable" ); / / Create a DataColumn instances DataColumn dValue = new DataColumn(); DataColumn dMember = new DataColumn(); dValue.ColumnName = "Id" ; dValue.DataType = Type
View state Hi , New to view state , and here is the issue : DataTable dtz = ViewState["GridWindowsService"]as DataTable; DataTable dt = new DataTable(); dt = dtz; dt.Rows.Add(dt.NewRow()); ViewState["GridWindowsService"] = dtz; dtz table is also having missing something ??? What you want to perform with view STate?? i want to set a datatable equal to the view state ( in this case it would be null datatset ) in which footer when there is no data in the grid ) I show you the simple example: DataTable DataTableA; protected void Page_Load( object sender, EventArgs e) { DataTableA = new DataTable (); DataTableA.Columns.Add( "Quantity" , typeof ( string )); DataTableA.Columns.Add( "Duration" , typeof ( string )); DataTableA.Rows.Add