|
It works:
var names = from n in db.Contacts
where n.Name.Contains("aaa")
select n;
foreach(var t in names)
{
t.Name = "xxx";
}
db.SubmitChanges();
Not works (no errors but the Name field does not change)
public class tmp
{
public string Name {get; set;}
public int ID { get; set; }
public string Group { get; set; }
}
var names = from n in db.Contacts
where n.Name.Contains("aaa")
select new tmp { Name = n.Name, ID = n.Id, Group = n.Group.Name };
foreach(var t in names)
{
t.Name = "xxx";
}
db.SubmitChanges();
how can I do this without fetching all database columns?
Thanks
|
|
|
|
|
Sorry, if you are trying to update the Name on the contact object, then you will need to select the contact object (as you do with the first code example).
In the second example you are creating a new object (with the same Name, Id and Group), and updating it's name. You are not updating the original contact object.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I thought about this, but I did hope it's my mistake. So, there is no way to have an "updateable select" using just a few of table columns? The original goal was something like:
dataViewGrid.DataSource = from .....
and permit updates, ... in grid having just 3-4 columns (not all 15).
|
|
|
|
|
Yes it should be possible to only retrieve 3-4 columns from a DB table and still allow those columns to be updated. This is assuming ofcourse that one of those columns is a unique identifier for the associated row (e.g. the Primary Key).
For your code, it really depends on what db.Contacts returns. Since I can't see that code, I'm assuming that it returns a list of Contact objects that have all 15 columns. In order to only return 3-4 columns, then the Contact object would need to only have the 3-4 columns.
If you can provide some more of the code that would help (either through email or here). Let me know if this doesn't make sense also. But basically, the "object" that holds the data for a single row in your table is what must be updated. Therefore, you would need to change how many columns the "object" has before the code you posted earlier.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
db.Contacts and 3 more classes are generated by sqlmetal, the solution would be to modify this classes to have properties just for database columns I need? (the primary key is in my "column-wish-list"). This probably would work but it seems to me way to complicated and across the program there are about 5 column combinations.
Thanks
|
|
|
|
|
I want to set the file of types in Open File Dialoge to a specific type such as ".bmp"
|
|
|
|
|
Why don't you read the documentation? OpenFileDialog has a property called filter which allows you to set file type.
|
|
|
|
|
could u please give me an example on how to use it !
|
|
|
|
|
As I already said in my first reply, why don't you read docs? Or google? Or search here, on codeproject? No one is going to do it instead of you. Learn googling.
|
|
|
|
|
i didnt say that i wanna some one to do it for , all i wanna is some help and thankx anyway for the adive.
|
|
|
|
|
If you read documentation, you will find everything you need.
|
|
|
|
|
|
How can we embed a xml file into dll file when deploying applications?
description:
when installing setup we are asking to enter "user Information". we want to store this information in a dll.
|
|
|
|
|
Probably through resources. You might want to google it.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
how to insert values which are inserted in a datagrid at runtime into database at runtime only. I`ve a datagrid i`ll insert values into grid at run time and i want to store them in database when i click save buton. How to store from datagrid
Chandrika
|
|
|
|
|
Through code behind with the save button. You'll have to code it yourself since no one knows what your database looks like.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi,
two questions
1. i want to bind a database table to a datagridview and few of the columns must have cell format as datagridview combo box ...
2. if question one is solved then..see to this....
one of the column contains item list along with its values
i am storing the item names in the combobox and the values as
cell.value...
now what i need is when i am retriving the database the particular columns must have cell type as combobox and the values for the cell must match the combobox list item
regards
sindhu tiwari
its me sid
|
|
|
|
|
sindhutiwari wrote: 1. i want to bind a database table to a datagridview and few of the columns must have cell format as datagridview combo box ...
Use ItemTemplate Field and use Combox in It!! your problem will solve
Steps
a)add a column to the gridview which is a TemplateField
b)Edit the templateField and drag ComboBox into the template!
sindhutiwari wrote: 2. if question one is solved then..see to this....
Try to do this first one , after that you can do this one also .
This is For your reference!!!
Reference!!!![^]
|
|
|
|
|
i neede it in desktop application
its me sid
|
|
|
|
|
Hi sindhutiwari,
1) First retrive the data from database to DataTable.
DataTable objDataTable = new DataTable();
objDataTable.Columns.Add("DataColumn1");
objDataTable.Columns.Add("DataColumn2");
dr = objDataTable.NewRow();
dr[0] = "data1";
dr[1] = "yes"
objDataTable.Rows.Add(dr);
2) Now you can bind this datatable to datagridview. You should set the "DataPropertyName" property of datagridview column.
grdView.DataSource = objDataTable;
this.grdColumn1.DataPropertyName = "DataColumn1";
this.grdColumn2.DataPropertyName = "DataColumn2"; // grdColumn2 is comboboxcell it contains 2 items (yes/no). other values not accepted.
Regards,
Gopal.S
|
|
|
|
|
I am developing a simple phone book application and i need to save the contact photo when adding new contact
and retrive it again when searching for them later.
|
|
|
|
|
This is very simple to do. just upload image corrosponding to the contact person and disply it from database.
you can store image in database as binary format
or
you can store image in a folder and store the path with data base corosponding image
e,g:
ID Name Address ContactNo Image_Path
------------------------------------------------------
1 MyName MyAddress 123456789 d:\AppFolder\MyName.jpg
2 UrName UrAddress 987654321 d:\AppFolder\UrName.jpg
Just Do in this way !!
While retrive with id, or name use image box to show the image
Any more query ??? Always welcome !!!
|
|
|
|
|
thankx alot. thats was very helpul
thank you again
|
|
|
|
|
i have another question please
how can i set the path for my picture to be saved in one of my soulotion folder like the bin folder for example without wirriting the hole path
c:\progrm\....\myproject\bin?
|
|
|
|
|
using System.IO
This will return the current working directory !!!!
Directory.GetCurrentDirectory()
|
|
|
|