|
Please see my edits to my original post.
I apologize for my misdirection.
|
|
|
|
|
Hi,
These are my review points.
1. You don't have a variable for DataAdapter.
2. What is the purpose of the DataAdapater if your codes are not filling this.
3. You don't have a columnName and data Type for dMember Variable.
4. Opening and Closing of Connection are not necessary for DataAdapter. Data
Adapter will automatically do this for you.
Here are the correct codes.
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = T:\Nasmeea\PSSZ.mdb";
conn.Open();
DataAdapter da = new DataAdapter("Select field1, field2 From [DivInfo]", conn);
DataTable dataTable = new DataTable("System_Setting");
da.Fill(dataTable);
DataColumn dValue = new DataColumn();
DataColumn dMember = new DataColumn();
dValue.ColumnName = "dValue";
dValue.DataType = Type.GetType("System.String");
dMember.ColumnName = "dMember";
dMember.DataType = Type.GetType("System.String");
dataTable.Columns.Add(dValue);
dataTable.Columns.Add(dMember);
conn.Close();
MessageBox.Show("Column Count:" + dataTable.Columns.Count.ToString());
MessageBox.Show("Row Count:" + dataTable.Rows.Count.ToString());
Regards,
modified on Tuesday, July 29, 2008 9:26 AM
|
|
|
|
|
Hi AMrk. Thanks for the information. I have tried the changes above and it still doesn't work.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi,
I wondering what went wrong!
I've tried on my oracle database and it is working perfectly before posting my solution to your problem.
Here are my exact code which almost the same with your codes.
System.Data.OracleClient.OracleConnection conn = new OracleConnection();
conn.ConnectionString = "Data Source=testDB;User ID=Claims;Password=claim2be;";
OracleDataAdapter da = new OracleDataAdapter("Select Key,Value From System_Setting", conn);
DataTable dataTable = new DataTable("System_Setting");
da.Fill(dataTable);
DataColumn dValue = new DataColumn();
DataColumn dMember = new DataColumn();
dValue.ColumnName = "dValue";
dValue.DataType = Type.GetType("System.String");
dMember.ColumnName = "dMember";
dMember.DataType = Type.GetType("System.String");
dataTable.Columns.Add(dValue);
dataTable.Columns.Add(dMember);
The output of my codes for column count is 4 my columns are Key,Value,dMember and dValue.
Please be specific with regards of actual and expected output, errors and othere information which will help us to resolve your problem.
Thanks,
|
|
|
|
|
HI mate. I think it has to do with OLEDB. Apparently you can not create extra columns with it. When trying to create the Column, specifying dValue and dMember to have the same Column names it throws an error saying that it can not create as it already exist but when checking the Table the column doesn't exist. One can apparently not create a permanent column with OLEDB.
Thanks for the help and advice.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
How you are checking whether the columns are added or not? From your code there should be two columns in the dataTable before it goes of of scope. Also I could not see the use of dataadapter/connection, Is there any which is affecting the existing variable?
*jaans
|
|
|
|
|
This is the modified code I have now. I only connect to the DB on button click even. From the count at the bottom of the code it picks up the correct table etc but it for some reason doesn't add the new column. I currently have 29 columns in the DB with approximately 2000 rows of data. It returns all that showing that I am successfully connecting and it is reading the correct table.
private void btnAddColumn_Click(object sender, EventArgs e)
{
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = T:\Nasmeea\PSSZ.mdb";
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * From [DivInfo]", conn);
DataTable dataTable = new DataTable("DivInfo");
da.Fill(dataTable);
DataColumn dValue = new DataColumn();
dValue.ColumnName = txtboxColumns.Text.ToString();
dValue.DataType = Type.GetType("System.String");
dataTable.Columns.Add(dValue);
dataTable.AcceptChanges();
conn.Close();
MessageBox.Show("Column Count:" + dataTable.Columns.Count.ToString());
MessageBox.Show("Row Count: " + dataTable.Rows.Count.ToString());
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi,
Please add these codes after the da.Fill(dataTable);
MessageBox.Show("Column Count:" + dataTable.Columns.Count.ToString());
MessageBox.Show("Row Count: " + dataTable.Rows.Count.ToString());
You have 4 messagebox. 2 before adding the dynamic columns and another 2 after the adding.
Let us know what are the outputs of the messagebox
modified on Tuesday, July 29, 2008 9:53 AM
|
|
|
|
|
Hi Mark. Apparently I have to use ActiveX objects to create the Columns as OLEDB can not add the columns on the "fly" permanently. I will have to readup on this.
Thanks for the help and advice. The code is correct and should work on any other type of database except for Access Databases.
Once I have found a solution I will post again.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi MArk. I added the MessageBox stuff in after the da.Fill and it pops up with 28 columns. After the conn.Close() statement the count is 29 which menas that it is creating the Column but for some reason it is not saving the change which I find very strange. I have tried to see if I could find something on ADO to do this but everything I have come across does exactly the same thing. Nothing different and most of the code samples and articles refer to DATAGRID and not the DB itself.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
hello, hru? I want to know is it possible in winforms c# to add sqldatasource like control that gives all the options of select, insert, update, delete, stored procedures etc etc .... OR any other alternate solution to make my development simple.
thanks in advance.
|
|
|
|
|
Yes, Use the DataAdapter and Connection Control.
|
|
|
|
|
hello friends
I am using a control ( com component ) which is generally used to work in visual basics
so presently i am getting two files with my exe under debug folder
AxInterop.xyz.dll
and
Interop.xyz.dll
Now i want to deploy this application, previously i used to do this by adding the dll in the GAC folder but now i am unable to do this ..
Please help me to solve this issue
Thanks and regards
Krazy programmer
Happy Programming
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
I am actually surprised you were ever able to move those DLLs to the GAC folder. Anyways...
If you deploy the two Interop dlls to the same directory as the .NET application(s) where they are used, and ensure that the COM component from which they were derived is registered somewhere on the PC (the System folder or some folder where your company prefers to register COM components), you should be fine.
If you are using a .NET setup project for deployment, then you probably want to ensure that the 'File Installation Properties' Register property for the COM component is set to vsdrfCOMSelfReg (assuming it is a registered COM component). The Interop DLLs do not get registered; dropping them in the same folder as the application that uses them will be fine.
|
|
|
|
|
Hi gurus, I'm looking for a collection that combines the functionality of a list and dictionary. I basically want to be able to keep the order in which the items are added and at the same time do fast lookup? O(log n) as opposed to O(n), does this thing exist or do I have to write it myself?
Regards
|
|
|
|
|
If you can use a SortedDictionary, it's loopup is a O(log n) operation.
Otherwise you need to write it yourself. Just wrap a List and a Dictionary in a class, write an Add method that adds an item to both collections, and properties to get the values by index and by key.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guess you have to write it yourself, like KeyList<T> with members List<T> and Dictionary<T> to which you delegate. But then I'm not a guru...
|
|
|
|
|
Thanks guys for your replies, seems like I'll have to write myself .. just wanted to be sure I'm not wasting my time in reinventing the wheel ..
|
|
|
|
|
Does SortedList in the System.Collections.Generic namespace not work for you? It has a GetByIndex method along with key lookup!
|
|
|
|
|
Thanks for your reply, actually I want to keep the same order in which items are inserted, this is why SortedListed and SortedDictionary are not suitable for the job ..
|
|
|
|
|
Greetings!
I'd like to do this:
I have a Button which defines the value of a bool Parameter:
public bool ListenMode { get; set; }
private void Button_Click(object sender, RoutedEventArgs e)
{
ListenMode = !ListenMode;
}
Further I have a Grid which can contain certain Items.
What I want to do is, that if ListenMode is true, and the next element clicked on is one of those Items, get the item.
The problem (if it is one) is, that I don't know how to catch all the next clicks while ListenMode is true.
Any suggestions would be apreciated.
PS: It's done in WPF if this is of any matter.
Thank you in advance,
eza
|
|
|
|
|
hi friends
i am working on a project. in this project we simulate a search engine to achieve some specific information about our users.
in this search engine i want to save the rank of a site in the database. but i dont know how can i get the rank of a site programmatically??? i write this application with c#.net
thank you for your reply.
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
First you have to specify what the rank for a web site should be in your application.
After that you should know what the input data needs to be so that you can collect it, and what formula to use to calculate the rank from the input data.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thank you
but i did it, i calculate rank t any site with my formula
but i want to save google page rank( with google formula) too.
there are some site to get u a google page rank if u enter the url address on it.
i want get the google page rank in win application with c#.net
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
I want to get the data while single or double clicking the row in the view grid in C#.NET2.0.
|
|
|
|