C# :: Get Collection Of Data From Database Through SQL Class?
Apr 26, 2015
In my WPF application i have a SQL class which i am trying to use to store all of my SQL queries so far this is working fine for when i want to return one piece of data like this:
public string GetEnquiry_ContactName(int EnquiryID) {
string ContactName = null;
//Try to do the following if not then show the error message.
try {
//Create the SQL Connection
SqlConnection cn = new SqlConnection(Models.M_GlobalVariables.GetConnection);
[Code] ....
But if i want to return a collection of data like this:
public ObservableCollection<CompanyNames> GetCompanyNames () {
public class CompanyNames {
public string CompanyName { get; set; }
public CompanyNames(string name) {
CompanyName = name;
[Code] ....
It does not work and i get 'Not all code paths return a value' and ''List_CompanyNames' is a 'property' but is used like a 'type''. But if i have it in my ViewModel like this:
//Code for the 'Company Names' dropdown box
public class CompanyNames {
public string CompanyName { get; set; }
public CompanyNames(string name) {
CompanyName = name;
[Code] ....
It works absolutely fine but the whole point of my SQL class is to have all my SQL code in that class instead of some of it in the ViewModel.
View 14 Replies
ADVERTISEMENT
Mar 19, 2014
I have a WPF project where I am using the entity framework. I have switched all my collection types to ObservableCollection and I am also using the PropertyChanged event. The only way my collections update is if I close the application then restart it. I got to the point where I just created a new application with 1 entity and 1 combobox to display a collection and I still can't get the collection to update. In my code below I am calling the AddCustomer method to add a customer name to the Customers ObservableCollection without success.
class ViewModel:INotifyPropertyChanged {
Model1Container context = new Model1Container();
public ViewModel() {
Customers = new ObservableCollection<Customer>();
UpDate();
[code]....
View 9 Replies
View Related
May 14, 2014
I have a program which generates lots of data points in 2D (x and y co-ordinates). Perhaps 1,000,000+ of these points. These are floating point numbers. The values all fall within a specific range -R/2 and +R/2.
I want to impose an 'imaginary' grid. Such that I can collect the number of each of these points falling within a specific grid location. The actual 'grid' size is variable.
Should I try and collate this data from my C++ program and then post-process it in some other s/w like matlab?
View 3 Replies
View Related
Sep 9, 2013
I am struggling with how to efficiently design my class objects to support the outlining of a collection of items. The collection would be sorted but would also have the ability to indent and outdent individual items representing a Parent and Child relationship (see attached).
An item could indent up to 5 levels deep. A summary level would be considered a Parent while items below the summary level would be consider as children.
View 6 Replies
View Related
Apr 8, 2015
I had assign to do a project using c# window form.Now I am doing a smart part of coding which is let the data in textbox and using keypress function with a enter,the data will save in database and show on datagridview.I had searching how to do it online but all of them using mysql or sqlcommand something to do it! But my project is using the code that already done and can access without mysql or sql coding... Using this code to connect and show in datagridview...
using (TMPB_attn_DAL dalObj = new TMPB_attn_DAL())
{
dataGridView1.DataSource = dalObj.GetRecords().Cast<TMPB_attn>().ToList();
dataGridView1.Refresh();
}
This is the function code for me to add data inside database,it can run but just still cant save.
private void txt_proximity_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == (char)13) {
if (BusinessLogicLayer.TMS_GET_PROXIMITY_VALID_TO_USE(txt_proximity.Text) == true) {
TMPB_attn row_tmpb_attn = new TMPB_attn();
[code] ....
View 3 Replies
View Related
Nov 24, 2013
I am writing a contact book program in C that will run in the terminal. I am going to create a file to store the data separately, but have run into a few question areas:
1) It has occurred to me that it might be more efficient to setup the program so that it sorts the contact info by info type rather than by running through an index of the contacts and then linking all of that contact's information to that index. So basically one part of the file would be phone numbers, the other contact names, and so forth with each piece of data linked to another piece within the data file that corresponds to the same contact. Am I wrong to think this is a more efficient way to set up the file?
2)How would you link the data information to other pieces of data corresponding to the same contact in C? My thought is to do it with pointers, but I didn't know if it were possible to have the pointers as I didn't know if the pointer would point "persistently" to the data once the file closed.As I felt this is a more "in general" question, I have chosen to omit my code from this post (especially since there is not much "meat" in it to speak of).
View 6 Replies
View Related
Feb 22, 2015
I can not do transferring data to textboxes from database.
="c#">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 MySql.Data.MySqlClient;
namespace WindowsFormsApplication1{
[code]....
I got the error this line:
read = cmd.ExecuteReader();
View 3 Replies
View Related
Mar 17, 2014
I want to connect an access database (.mdb) to my Windows Forms application - this I can do and I have no problems viewing my table in server explorer.
Some code example or template that I can use as a base to learn from - I have literally trawled Google and Youtube and cannot find what I am after.
What I want to do is have a basic form, 2 text boxes and a button to save the data to my database.
FirstName and LastName are the 2 boxes.
View 6 Replies
View Related
Mar 4, 2014
Background: I've created a projected and added a mdf database file to it.
I am attempting to fill my datagridview with data from a table that I've added to my mdf file.
I am having a hell of a time figuring out the correct connection string and datasource file path for it.
I've decided on using OleDB because that's what I am most familiar with.
I clearly see the rule "Don't tell us to give you code!" but I cannot find a good tutorial from START to FINISH on how to do what I am trying to do.
As stated, I think my connection string is wrong. Even if I change it to
OleDB (string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdf"
I get a new error saying it cannot recognize the database format.
public partial class DataViewer : Form {
string conStr = "Provider=SQLOLEDB;Data Source=Database.mdf";
DataSet dS = new DataSet();
DataSet tdS = new DataSet();
OleDbConnection con = null;
[Code] ....
View 2 Replies
View Related
Apr 19, 2014
Exporting the data from the sql database to excel directly.this code is not working and i am not getting file in particular location. My connection string is :
Data Source=aswin-pcsqlexpress;Initial Catalog=pro;Integrated Security=True
using Excel=Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication5 {
public partial class Form1 : Form {
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["SqlCon"].ToString());
[code]....
View 1 Replies
View Related
Jan 17, 2013
i am student working on a project in c# to maintain the datas from a solar battery monitoring.i already imported the datas from the battery monnitoring and saved them in mysql database and retrived the data in c#.
i have problem in retriving the data in accordance with the date and time range selection.
what i am trying to do is there are more than 1000 datas in the table if i select two date and time the datas in the table should cross check these dates and show all the datas in the table in between those date&time
View 3 Replies
View Related
Feb 12, 2014
using System;
using System.Collections.Generic;
using System.ComponentModel;
[Code]....
find the attachment.
Data is displaying in grid view but when i enter the particulars it's not inserting in to DB & grid view.
View 1 Replies
View Related
Jan 5, 2013
I created a class (let call it X) which contains the structure to store the data from my data base. Them I have a class (call Y) which will contain a list for each row in my data base. Third, I have a class with thousands variables (Z). What I am trying to do is to take the list of objects (Y) that contains the data to initialize Z. What I want to now if I can do something like that.
Imaging that one of my rows contain the following data:
Type Nameofvariable etc...
"static const double; MNFAIL ; 0; 0; 0,25"
In my list I have a node with contain this data
I want to use the field Nameofvariable to initialize the variable called MNFAIL contained in my class Z.
Is it possible in C++
View 3 Replies
View Related
Aug 27, 2013
What does collection of parameters as argument of a function in C mean? Also any place I can refer to find those parameters?
Googling gives me Parameters and Arguments But not really sure whether that is what is needed.
View 6 Replies
View Related
May 8, 2014
I have a class that loads the contents of a XML file into their respective object types and stores those objects in a list. Each object has its own list of objects with properties the program will later modify.
The problem I am currently having is that after looping through the objects and modifying the necessary properties the modifications do not persist. This leads me to believe I am modifying a copy of the object rather than the object I think I am modifying. I am not sure why this is happening as I believe I should be modifying the object that is referenced in the collection.
What I have tried, I started using LINQ to get the object I am looking to modify. After a little more research I don't think this can work properly due to the LINQ query returning a new object(copy of the object). Currently I am using nested foreach loops which still are not behaving the way I expect as the properties I am setting are not making their way back to the original object.
The PopulateLogSheet() in the following class is where the problem loop is.
class ChillerCheckCollection {
public List<Chiller> chillers = new List<Chiller>();
public void LoadChillers(string filePath) {
var availableChillers = (from chiller in Xdocument.Load(filePath).Descendants("chiller")
select new Chiller
[Code] ....
And here are the other classes referenced in the above class.
class Chiller {
public IEnumerable<LogSheet> chillerLogSheet = new List<LogSheet>();
public int chillerID;
[Code] ....
View 2 Replies
View Related
Jul 6, 2012
I am busy with a project, it is going to consist out of 3 different windows which is logic enough for this whole code to be interactive.
It must be able to pull data into a windows form, displaying it into a textbox, and when you click on the textbox it needs to open up another window where you will have a windows form that will display data as the code loops through the questions in the database.
I am not sure how to push the data that has been selected on the database to the next window..
Here is my code for the first window:
;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form {
//SqlConnection myConnection = new SqlConnection("Data Source=(local);Initial Catalog=KnowledgeEssentials;Integrated Security=SSPI");
//int intType = 0;
public Form1()
[code].....
With the second window the data in the table needs to be displayed and each row from the table needs to have a checkbox next to them, so that if the check box is checked, the relevant information of the checked row will show up in the 3rd window... so MY question is, HOW do I pull that data from that specific database and let it show in the listcheckbox?
View 1 Replies
View Related
Mar 15, 2015
I have a window in WPF which I want the user to use to enter the information for a COM Port.
The intent is to populate two ComboBoxs from a two different ObservableCollection<string> which I am having no luck with.
I don't think that it is a DataContext issue, as I am able to get something from the ComRateList when the window opens, but nothing from BaudRateList. Either way I have included the way that the window is opened and DataContexts assigned...
When the code runs, the COM Port list is updated when the window opens - However, it is not updated when the user reclicks the ComboBox which was my intended behavour.
All the adds for the BaudRateList do not populate the ComboBox for the baud rates on start up, nor when the code is running.
When I step through the code, I can see all of the BaudRateList items being added... The window is called by the main window's datasource like so...
OpenSerialCommunication OpenView = new OpenSerialCommunication();
OpenView.Show();
This opens fine.
The OpenSerialCommunication.xaml is as follows: (Note that any business names have been replaced with [snip])
<Window x:Class="[snip].SerialCommunication.OpenSerialCommunication"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:serial="clr-namespace:[snip].SerialCommunication"
Title="Open COM Port - [snip]" Height="300" Width="300">
<Grid>
[Code] ....
View 1 Replies
View Related
Dec 22, 2014
When server send data then client receive that data, in C# windows services where data receive continuously (Using IP Address and port number) . This below code writing in console application . i want implement same logic in windows service side. but i want data receive continuously.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[Code]....
Above code write in console application, same logic implementing in windows service, but i want data receiving continuously
View 3 Replies
View Related
May 30, 2014
I seem to have reached a dead end in a program I am attempting to write.The purpose of the program is find the smallest, largest, and average values in a collection of N numbers. It needs to get the value of N before scanning each value in the collection of N numbers.I'm having trouble creating comparisons for each set. I have a feeling because of the way I structured my program, I'm unable to make a proper comparison. Maybe my approach was wrong as soon as I got to the for statement to loop N sets and N numbers.Here is my code so far:
Code:
#include <stdio.h>
int main (void)
{
int num_sets, num_of_integers;
int count, count2, set, sum = 0;
int num, avg;
}
[code]....
/* Here is where I would continue to attempt to make a comparison between sets to determine smallest to largest */
return 0;
View 5 Replies
View Related
Mar 1, 2013
private String[] GetExcelSheetNames(string excelFile) {
OleDbConnection objConn = null;
SqlConnection objSqlConn = null;
System.Data.DataTable dt = null;
try {
[code].....
Now I can fatch all the excel sheet belongs to the Excel File.But How can I check "If and Only If the sheets are havin Underscore in their name(eg. student_data,teachers_data) then only the data of the sheets will populate in tha data base"
View 2 Replies
View Related
Aug 27, 2013
I'm trying to make an unordered_map with a key of std::string and a data type of my own class, "Variable". This is my code that I've done:
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
class Variable { // The class that I want to have as data type
public:
Variable(double value) : _value(value) {}
[Code] .....
This code works just fine when I use double instead of "Variable", but the moment I put in the class "Variable" instead it gives my this massive error:
(cut for clarity)main.cpp|25|error: conversion from 'std::_Hashtable<std::basic_string<char>, std::pair<const std::basic_string<char>, Variable>, std::allocator<std::pair<const std::basic_string<char>, Variable> >, std::_Select1st<std::pair<const std::basic_string<char>, Variable> >, std::equal_to<std::basic_string<char> >, std::hash<std::basic_string<char> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, true, false, true>::_Insert_Return_Type {aka std::pair<std::__detail|
View 4 Replies
View Related
Dec 11, 2014
i have private data look like Peiceorder peiceOrders[20]; it looks like a array but does not have name type like int or char? why is that and what should I use the data should I write Peiceorder peiceOrders[20]=........ like that? or?
View 1 Replies
View Related
Oct 14, 2012
I am studying the use of static data into classes and the code below is returning an error ...
#include <iostream>
using namespace std;
class REC {
private:
static int n; //Dado que sera unico na classe e alterado por todos os objetos
[Code] .....
The error:
main.obj:-1: error: LNK2001: unresolved external symbol "private: static int REC::n" (?n@REC@@0HA)
Note: I'm using QT Creator
View 3 Replies
View Related
Oct 27, 2014
When we want to use custom classes for the STL set data structure, how to do it?
I look around and see people passing comparators, overloading operator(), and also overloading operator< in the class itself.
Which one's the idiomatic c++ way?
View 1 Replies
View Related
Apr 25, 2013
I'm currently building a new data structures that will be used in monte carlo generators (and so will be constructed several million times) and I'm wondering what's the best way (computer-speed-wise) to pass the data to the constructor. I am currently doing it using references and passing arrays as pointers like this:
Code:
class particle{
public:
particle(double *ar,int &id):IDup(id){
for (int i=0;i<5;++i)
Pup[i]=ar[i];
}
int IDup;
double Pup[5];
};
I'm assuming that since using references has no need to create a temporary memory slot it's more efficient .....
As for the arrays: is there a way for me to pass them as reference as well? (not using c++11), I'm using arrays instead of vectors as much as I can because I assume that vectors, being more advanced data structures, would take more time to create.
View 14 Replies
View Related
Feb 10, 2013
I'm having trouble understanding on how to actually store into a container from another class. Any simple example.
View 9 Replies
View Related