Members I have a question how to connect to sql server tables of a database with this proect's data.
Can you suggest .
Members you can see that inside the bin\debug\Conta ctManager.state now in this ContactManager. state is the file where the data is getting stored when I am running the proj.
There is a _stateFile in the ContactReposito ry.cs where the values are getting stotred.This variable is later on used for all the operations.
My question is how to connect to sql server instead to this ContactManager. state file
now inside contactreposito ry.cs file
<code> - using System;
-
using System.Collections.Generic;
-
using System.IO;
-
using System.Linq;
-
using System.Runtime.Serialization.Formatters.Binary;
-
-
namespace ContactManager.Model
-
{
-
public class ContactRepository
-
{
-
private List<Contact> _contactStore;
-
private readonly string _stateFile;
-
-
public ContactRepository()
-
{
-
_stateFile = Path.Combine(
-
AppDomain.CurrentDomain.BaseDirectory,
-
"ContactManager.state"
-
);
-
-
Deserialize();
-
}
-
-
public void Save(Contact contact)
-
{
-
if (contact.Id == Guid.Empty)
-
contact.Id = Guid.NewGuid();
-
-
if (!_contactStore.Contains(contact))
-
_contactStore.Add(contact);
-
-
Serialize();
-
}
-
-
public void Delete(Contact contact)
-
{
-
_contactStore.Remove(contact);
-
Serialize();
-
}
-
-
public List<Contact> FindByLookup(string lookupName)
-
{
-
IEnumerable<Contact> found =
-
from c in _contactStore
-
where c.LookupName.StartsWith(
-
lookupName,
-
StringComparison.OrdinalIgnoreCase
-
)
-
select c;
-
-
return found.ToList();
-
}
-
-
public List<Contact> FindAll()
-
{
-
return new List<Contact>(_contactStore);
-
}
-
-
private void Serialize()
-
{
-
using (FileStream stream =
-
File.Open(_stateFile, FileMode.OpenOrCreate))
-
{
-
BinaryFormatter formatter = new BinaryFormatter();
-
formatter.Serialize(stream, _contactStore);
-
}
-
}
-
-
private void Deserialize()
-
{
-
if (File.Exists(_stateFile))
-
{
-
using (FileStream stream =
-
File.Open(_stateFile, FileMode.Open))
-
{
-
BinaryFormatter formatter = new BinaryFormatter();
-
-
_contactStore =
-
(List<Contact>)formatter.Deserialize(stream);
-
}
-
}
-
else _contactStore = new List<Contact>();
-
}
-
}
-
}
.
</code>
now in this file you can see that - _stateFile = Path.Combine(
-
AppDomain.CurrentDomain.BaseDirectory,
-
"ContactManager.state"
-
is there .
Now to connect it to the sqlserver what I have to do is instead of the binary file "ContactManager .state " ....I want a it to be connected to a *.mdf .
How to do this please suggest me .
This is an open source project.
for the detail explanation please see the two attached files with this question which have attached with this question.
The code can be downloaded from the website:
1. Go to www.informit.com/title/9780672329715.
2. Click Downloads.
3. Click one of links that appear, and the download should start automatically.
Mar 21 '10
17 9289
tlhintoq ,
You have got it .In the project they have used the binary data file .
I want to use the sql server and a table to store all the data .
tlhintoq the queries of all the insert/update/delete are to be operated on that table.
I know the queries.
Database connection also i know .
But the problem is if you see in Address.cs there are
private string _city;
private string _country;
private string _line1;
private string _line2;
private string _state;
private string _zip;
these properties.
Also in Contact.cs there are these following properties
private Address _address = new Address();
private string _cellPhone;
private string _firstName;
private string _homePhone;
private Guid _id = Guid.Empty;
private string _imagePath;
private string _jobTitle;
private string _lastName;
private string _officePhone;
private string _organization;
private string _primaryEmail;
private string _secondaryEmail ;
Now I have to pass them to the table sql server.
In the file ContactReposito ry.cs
there is
private List<Contact> _contactStore;
private readonly string _stateFile;
So that means that in the list _contactStore the all properties of contact are passed
And in the following code
public ContactReposito ry()
{
_stateFile = Path.Combine(
AppDomain.Curre ntDomain.BaseDi rectory,
"ContactManager .state"
);
Deserialize();
}
The binary file is getting the values.
Now what I have to do ...Please tell me.
Please do not get angry if I am asking some silly questions(It is because I am fresher)
Please help
tlhintoq 3,525
Recognized Expert Specialist
I will ask you again... Did you bother to walk through the two tutorials?
Just do the tutorials from start to finish. Don't try to apply them to your problem right now. First learn on a small scale how to interact with a database. Learn how to update small projects, small tables. Learn how to do the queries.
*THEN* take that new understanding and try to apply it to your larger project.
First you asked for help on how to do an update. Then you responded that you know how to update/query/connect/etc.
I know the queries.
Database connection also i know.
Then you say the problem is that you have properties. Why are properties such as a name or address a problem? Isn't that the sort of data you are wanting update?
Without asking others to download your entire project and do all your work for you... what exactly is the problem? Do you need help updating a database? Do you need help serializing a class?
Hello Experts,
i m also a part in this project ...
Here is the proper question .... i hope you guys can help us in this issue ...
The actual WPF project code that we have using this concept :
Taking data from a binary file and utilizing it in project .
What we want to do is ... instead of this binary file we want to take data from MSSQL database .
Here i m able to do mssql connection and i get my database values in to this application .
The Problem was , the data has to be formatted in a list type of way , so that we can utilize ...
See the following code ... -
private void Deserialize()
-
{
-
if (File.Exists(_stateFile))
-
{
-
using (FileStream stream =
-
File.Open(_stateFile, FileMode.Open))
-
{
-
BinaryFormatter formatter = new BinaryFormatter();
-
-
_contactStore =
-
(List<Contact>)formatter.Deserialize(stream);
-
}
-
}
-
else _contactStore = new List<Contact>();
-
}
-
this is the function which takes binary data from file and passing it to application ...
this is the following line doing that specific operation on above function ... -
_contactStore =
-
(List<Contact>)formatter.Deserialize(stream);
-
so i have to alter this piece of code to replace my mssql data instead of this binary data .
i get my mssql data in some string type variables . now i have to store those values to _contactStore object , so that application can use that . Here comes the problem . this _contact Store object requires list type of input . so i assembled my mssql values into list type and i tried to pass there ... but it is not accepting that .....
this is the actual problem what we are having .... can any one help us on this ...
tlhintoq 3,525
Recognized Expert Specialist
this _contact Store object requires list type of input .
Does it? _contactstore is a List<> of Contact objects. - private List<Contact> _contactStore;
There is nothing here that tells us what data is *in* a Contact. Maybe it also contains one or more List<> variables. Maybe it doesn't. If you say a Contact object requires a List<> type as its input then we have to beleive you, but its seems unlikely. I would expect a Contact object to have a lot of properties such as - _FirstName
- _LastName
- _StreetAddress
- _City
and so on.
Regardless what it contains you need to make a new Contact object and .Add it to the List<> http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
Sir I think you have not yet seen the project.I am sure if you see it once you can give the exact solution. ---It is my earnest request to you if you download the project from http://www.informit.com/store/produc...sbn=0672329859
I know you are too busy , but it will be your kind benevolence if you once glance upon it . It won't take more than 2 sec to download sir.
Sir the Contact.cs is as follows
And the Address.cs is as followes-- -
using System;
-
-
namespace ContactManager.Model
-
{
-
[Serializable]
-
public class Address : Notifier
-
{
-
private string _city;
-
private string _country;
-
private string _line1;
-
private string _line2;
-
private string _state;
-
private string _zip;
-
-
public string City
-
{
-
get { return _city; }
-
set
-
{
-
_city = value;
-
OnPropertyChanged("City");
-
}
-
}
-
-
public string Country
-
{
-
get { return _country; }
-
set
-
{
-
_country = value;
-
OnPropertyChanged("Country");
-
}
-
}
-
-
public string Line1
-
{
-
get { return _line1; }
-
set
-
{
-
_line1 = value;
-
OnPropertyChanged("Line1");
-
}
-
}
-
-
public string Line2
-
{
-
get { return _line2; }
-
set
-
{
-
_line2 = value;
-
OnPropertyChanged("Line2");
-
}
-
}
-
-
public string State
-
{
-
get { return _state; }
-
set
-
{
-
_state = value;
-
OnPropertyChanged("State");
-
}
-
}
-
-
public string Zip
-
{
-
get { return _zip; }
-
set
-
{
-
_zip = value;
-
OnPropertyChanged("Zip");
-
}
-
}
-
}
-
}
-
tlhintoq 3,525
Recognized Expert Specialist
Sir I think you have not yet seen the project.I am sure if you see it once you can give the exact solution. ---It is my earnest request to you if you
You're right. I haven't downloaded your project, nor am I going to. Someone else with more free time might. But frankly, I don't make it a habit to download unknown code and run it on my PC. Nor do I make it a habit to completely debug other people's projects.
You provided the code for your Contact class. As I thought, it does not have a List<> in it, but a bunch of properties as one would suspect. Which means your original statement that it requires a List<> as input is wrong.
this _contact Store object requires list type of input .
i get my mssql data in some string type variables . now i have to store those values to _contactStore object
Stop right there. _contactstore is not an object. It is a list of objects. It is a List<> of Contact objects. A List<> is a fancy array if that helps. So _contactstore is an array of Contact objects.
If you are getting your mssql data as a bunch of strings that's great. Make a new Contact with them since your Contact object is also a bunch of string properties.
- public class Contact : Notifier
-
{
-
private Address _address = new Address();
-
private string _cellPhone;
-
private string _firstName;
-
private string _homePhone;
-
private Guid _id = Guid.Empty;
-
private string _imagePath;
-
private string _jobTitle;
-
private string _lastName;
-
private string _officePhone;
-
private string _organization;
-
private string _primaryEmail;
-
private string _secondaryEmail;
Sir
I have failed to send the data to the
_contactStore
in the
_contactStore =
(List<Contact>) formatter.Deser ialize(stream);
Can you please tell me in which format the data has to be send so that _contactStore will accept the data and subsequently that can be stored in table in sql
I am sorry to say I have never worked on the "storing list of objects which can be passed to the table in database in sql server"
Just give me an example or refer a url so that I can come to know that .
It will be your kind benevolence if you suggest.
tlhintoq 3,525
Recognized Expert Specialist
From your own code:
_contactStore is a List of Contact objects. - _contactStore = new List<Contact>();
And a Contact has a bunch of public properties that make sense for a Contact: - public string ImagePath
-
{
-
get { return _imagePath; }
-
set
-
{
-
_imagePath = value;
-
OnPropertyChanged("ImagePath");
-
}
-
}
-
-
public string FirstName
-
{
-
get { return _firstName; }
-
set
-
{
-
_firstName = value;
-
OnPropertyChanged("FirstName");
-
OnPropertyChanged("LookupName");
-
}
-
}
-
-
// and so on with all the other properties of a Contact
Can you please tell me in which format the data has to be send so that _contactStore will accept the data
You have to send your data to the Contact object the way it is defined. EX: For the FirstName send it a string as defined in line 11 of the code above.
Just give me an example or refer a url so that I can come to know that .
This isn't the complicated part. This is a basic property. http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx
Please don't be offended when I say "If you're having this much trouble in such basic areas then this project may be beyond what you/your company can do."
Maybe it's time to tell your boss that you don't have the training to complete this project. It might be the nudge (s)he needs to get you some more training which can only further your career.
Either that or your company needs to quit underbidding qualified coders on projects that they don't have the expertise to handle - because it is unfair to their staff (you) to expect results they aren't prepared to produce. Nobody needs that kind of pressure placed upon them. It just makes people miserable.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Refky Wahib |
last post by:
Hi
I need Technical Support
I finished a Great project using .Net and SQL Server and .Net Mobile
Control
My Business case is to implement this Program to accept about 1
Million concurrent users
So I designed the project as master Node that has all administration
|
by: ebrahimbandookwala |
last post by:
Hi , I am trying to connect to MS Sql server 2000 from Java (1.4.2 /
1.5 ). I installed my Sql Server(8.00.382) from the one supplied with
VS.NET 2001. When I installed it on my laptop it did not ask me for a
user name and password. After install when I re-started my machine I
see the server started up with a green light. Now when I connect to the
server from VS.NET it works fine. This is because VS uses windows
integrated security. I...
|
by: Lauren Quantrell |
last post by:
I'm wondering which is the best approach using an Access2K front end
and a SQL Server 2K backend.
I have a stored procedure running three INSERT INTO statements that
inserts records into three different tables.
Should I use the ADP project connection as set through the Access
Connection window:
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
|
by: Jim Devenish |
last post by:
I am continuing my exploration about upsizing to SQLServer from Access
2000.
I have a split database with a front-end and a back-end, each of which
is A2K. I have spent some time in bookshops trying to learn about the
way forward and trying to decide which to buy. The bit I am interested
in is usually at page 900 and I am not sure whether I want to buy the
first 800.
It appears that upsizing creates an Access project as the...
|
by: Dave Dudley |
last post by:
Hi,
I have a new ASP .Net project that has been developed on our
development machine and connects to SQL Server 2000 on the same
machine. It is connecting via a connection string similiar to:
Data Source=;Initial Catalog=;uid=;Password=
| |
by: Galina Grechka |
last post by:
Hi
Recently I started get error message every time when trying to open web
project from Microsoft Visual Studio.Net:
Unable to open Web project. The path does not correspond to URL. The two
need to map to the same server location. HTTP Error 404: Object Not
Found.
It appears that our web server has several IP addresses. The work around
is: delete from DNS all IP addresses except the one I'm connecting to,
|
by: Dan Sikorsky |
last post by:
Can I use SQLServer 2000 with ASP.NET 2.0 instead of SQLServer 2005, and use
the .Net 2.0 Membership functionality?
I've setup my Login page, controls, etc., and now it's time to use the Web
Site Administration Tool (WAT) but it won't sense my SQLServer 2000
database.
|
by: CriticalJ |
last post by:
I have several projects that have been working for at least four
years. Last Thursday, the connections for these projects began
dropping immediately upon opening the project. When I test the
connection, the connection will succeed. However, upon closing the
connection dialog box, the database temporarily connects and then
drops. This happens for both Access 2k and Access 2003. I spent
Thursday and Friday trying to get things back to...
|
by: adjo |
last post by:
I am working on an app with an Access2002 frontend and Sql2005
backend. I have to use integrated security. I want to prevent my users
from altering data in another way than via the frontend.
It looks to me that the mechanism to do it is the Sqlserver
sp_setapprole procedure. Works fine when programming directly to
Sqlserver, and also een Access Data Project at first sight seems to
work as it should via the call to the sp_setapprole proc....
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |