I have used my Dataset all over the project without any problem.
When I Add a new form , the Dataset is not recognized in it - JUST THE NEW FORM.
It says :
The name 'mydataset' does not exist in the current context
I have checked using System.Data.SqlServerCe; using System.Data.SqlClient; is in the form.cs.
I tried to declare new one in form.cs and it doesn't work.
form.cs :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
namespace O2
{
public partial class ProductSelect : Form
{
public ProductSelect()
{
InitializeComponent();
}
private void ProductSelect_Load(object sender, EventArgs e)
{
//DatabaseDataSet ds = new DatabaseDataSet();
foreach (DataRow row in mydataset.Products.Rows)
{
listBox1.Items.Add(row["Product_Name"]);
}
}
}
}
Any help ?
Edit :
form2 where mydataset works perfect (without declaring it) :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Data.SqlClient;
namespace O2
{
public partial class SalesBill : Form
{
public SalesBill()
{
InitializeComponent();
}
private void SalesBill_Load(object sender, EventArgs e)
{
foreach (DataRow row in databaseDataSet.Clients.Rows)
{
listBox1.Items.Add(row["Client_Name"]);
}
}
}
}
If you are using the designer for configuring the form and elements on it, from toolbox in Data section, drag an DataSet and drop it on form. You can select either typed dataset or untyped dataset
If you want to create and use dataset from code, consider declaring your dataset variable and create an instance of your typed or untyped dataset.
open form 2 at designer you probably will see a component with name databaseDataSet in component tray of it. It seems you are using a typed dataset.
And if you look at Data Source window (Shift+Alt+D) you will see a node of DatabaseDataset with some child node that are your tables.
You can drag clients table and drop it on form.
In .NET you declare a dataset like this:
DataSet myDataSet = new DataSet();
You can declare DataSet as global
public static readonly DataSet MyDataSet = new DataSet();
And access in other forms as
CLassName.MyDataSet; // ClassName is that in which you declare your dataset
But the recommended way is that, you need to add DataSet from toolbox or from new item dialog and add required tables into it.
Related
hi im sorta new to doing projects myself but one of my first tasks was to make a btec grade to ucas points converter by allowing the user to select their grade from the combobox and it would show in a label the correlating grade
however i dont know how to get the selected combobox item to change the label for each different grade
i tried using a an if statement but i realised that it comes up with error CS0029
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace btec_to_ucas
{
public partial class Form1 : Form
{
string PPP = "48";
string MPP = "64";
string MMP = "80";
string MMM = "96";
string MMD = "112";
string DDM = "128";
string DDD = "144";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1 = PPP)
{
label1.Text = PPP;
}
}
}
}```
Problem is here: if (comboBox1 = PPP). In this case, comboBox1 is the whole combo box object, with its items, selected index, size, etc. That will never be equal to the string "48". You want to look at the value that has been entered. Try comboBox1.SelectedText.
See:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox?view=netcore-3.1
How to display Filenames in Gridview on the basis of date selected from two calendar controls (DateFrom to DateTo) in asp.net c#. I have Gridview control and Two calendar controls. when user will select Dates in calendar control i want to display stored files in the Gridview between selected months range.
Try following :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication24
{
public partial class Form1 : Form
{
const string FOLDER = #"c:\temp";
public Form1()
{
InitializeComponent();
dateTimePickerStart.Value = DateTime.Parse("1/1/2017");
dateTimePickerEnd.Value = DateTime.Now;
string[] files = Directory.GetFiles(FOLDER).Where(x => (File.GetLastWriteTime(x) >= dateTimePickerStart.Value) && (File.GetLastWriteTime(x) <= dateTimePickerEnd.Value)).ToArray();
}
}
}
I have a situation where I have to disable certain controls on database value change.
For that I have used following code.
Here I am disabling the controls in the panel on 0 value and on any other values I am enabling it.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class test_control : System.Web.UI.Page
{
string test1;
List<double> _data = new List<double>();
public DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
GetData();
}
private void GetData()
{
int maxId;
using (SqlConnection dataConnection = new SqlConnection("Data Source=localhost\\SQLEXPRESS;Initial Catalog=MCAS;Integrated Security=SSPI"))
using (SqlCommand dataCommand =
new SqlCommand("select top 1 RunMode from MCASMonitoring_Rev1 order by Id desc", dataConnection))
{
dataConnection.Open();
maxId = Convert.ToInt32(dataCommand.ExecuteScalar());
TextBox1.Text = maxId.ToString();
if (TextBox1.value == 0)
{
Panel1.Enabled = false;
}
else
{
Panel1.Enabled = true;
}
}
}
}
But the situation is that I have to refresh the page to achieve this operation. But What I want is that I need it in runtime without refreshing the entire page.
SnPandya....
Suggestion 1
Panels should be disable based on DB values...So definitely once you have to come across server side.
Now, once you have DB values then you can call javascript from serverside and disable any controls you want........
Suggestion 2
Put your controls inside "Updatepanel" then you will not feel any page postback
This is the code in my class i have:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
namespace Magnifier20070401
{
public partial class MagnifierForm : Form
{
public MagnifierForm(Configuration configuration, Point startPoint)
{
InitializeComponent();
//--- My Init ---
mConfiguration = configuration;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = mConfiguration.ShowInTaskbar;
TopMost = mConfiguration.TopMostWindow;
Width = mConfiguration.MagnifierWidth;
Height = mConfiguration.MagnifierHeight;
// Make the window (the form) circular
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mImageMagnifier = Properties.Resources.magnifierGlass;
On the Properties im getting: Error 1 The name 'Properties' does not exist in the current context
I added this Form as Existing item to my project and im getting an error on this Properties.
And i have the magnifierGlass image in the Resources.
Found it needed to add my project name before the properties:
mImageMagnifier = ScreenVideoRecorder.Properties.Resources.magnifierGlass;
Now it's working thanks.
I want to position an image on the page the user is looking at, however I cannot find how to get the currently visible page/scroll in pixels.
Anybody know which object and property could give me that?
Are you trying to control Word from outside Word or is it an integrated control?
I think you want: Object oMissed = doc.Paragraphs[1].Range;
This code below is for an InlineShape, not Shape object. Shape object is for text-wrapping.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
namespace WordAddIn3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Word.Application wdApp = Globals.ThisAddIn.Application;
Word.Document doc = wdApp.ActiveDocument;
string fileName = "c:\\testimage.jpg"; //the picture file to be inserted
Object oMissed = doc.Paragraphs[1].Range; //the position you want to insert
Object oLinkToFile = false; //default
Object oSaveWithDocument = true;//default
doc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed);
}
}
}
Microsoft: HOWTO: How To Get 32-bit Scroll Position During Scroll Messages
Similarly, you may want to look at this SO question on How do I get the scroll position from Microsoft Execl -- which I just realized was asked by you..