hi people,
i am currently doing database C# using visual C sharp express and i am really new towards database programming. I actually taken my database from mc access using oledbconnection.

One of the column in my database contain many words seperated by a comma in each particular row. I am currently using oledbdatareader to read my database but i realise i only can read the whole column at a time instead of row by row.

Can anyone teach me how to obtain the words from my database and count the number of words i have per row after connection? Thanks in advance.

>i realise i only can read the whole column at a time instead of row by row.

You are wrong.

You can read read the whole set of data returned by the SQL query row by row if you use OleDbDataReader.

You select a row, get the string from the required column and then split that string in the array of strings delimited by comma. And then finally count the number of strings in that array. Need a code? post here.

okayy so currently my code is

private static OleDbConnection con;
 
con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=Assignment.mdb");.
                
con.Open(); //connection must be openned
                
OleDbCommand cmd = new OleDbCommand("SELECT * from main", con);                

 OleDbDataReader reader = cmd.ExecuteReader(); 
               
 while(reader.Read()) 
  {
 
   Console.WriteLine(reader.GetValue(1).ToString() + " = " + reader.GetValue(3).ToString());  // From here i am only able to get the whole column from 1 and 3 whereby column 3 is my list of words
 }

I heard about delimited and putting my list into array but actually i am doing a database which contain an object as the first column and having many words describing the object at the next column. Thus i have many words assign to one object and there are many object either. Hence i am quite confuse about how to put all the words into array and at the same time assign to their respective objects.

I really need your guidance in this. Thanks alot(:

Does anyone know the solution to this? sorry i really need help. thanks in advance

Post your assignment.mdb file here and I will give you the code. This thread has been open too long.

okayy so currently my code is

private static OleDbConnection con;
 
con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=Assignment.mdb");.
                
con.Open(); //connection must be openned
                
OleDbCommand cmd = new OleDbCommand("SELECT * from main", con);                

 OleDbDataReader reader = cmd.ExecuteReader(); 
               
 while(reader.Read()) 
  {
 
   Console.WriteLine(reader.GetValue(1).ToString() + " = " + reader.GetValue(3).ToString());  // From here i am only able to get the whole column from 1 and 3 whereby column 3 is my list of words
 }

I heard about delimited and putting my list into array but actually i am doing a database which contain an object as the first column and having many words describing the object at the next column. Thus i have many words assign to one object and there are many object either. Hence i am quite confuse about how to put all the words into array and at the same time assign to their respective objects.

I really need your guidance in this. Thanks alot(:

Store a string in a string variable and then use this code.

string todelimit="";
  string[] sep= {","};
  string[] stringarray = todelimit.Split(sep, StringSplitOptions.None);
  string wordcount = stringarray.Length;

thanks to thewebhostingdi but where do I put this code in or should i say after putting in the getvalue which only read in the whole column, how can i put the list of words inside. I am sorry if i am asking a very basic question becasue i really know nuts about it and are still learning. Thanks for the help

thanks to thewebhostingdi but where do I put this code in or should i say after putting in the getvalue which only read in the whole column, how can i put the list of words inside. I am sorry if i am asking a very basic question becasue i really know nuts about it and are still learning. Thanks for the help

Why don't you post your .mdb file up here and we can help you? You're not giving column names and the question is vague. Post the database and you will receive help.

Sorry i couldnt upload my mdb file but this is how my database will look like

Object Description of the object
object1 big, round, dangerous, big, ball, emergency, loud
object2 sharp, loud, produce a sound, loud, loud
object3 big, sharp, message coming in, emergency, alert, red, sharp, big
object4 square, alert, loud, colourful, big, big

The user will be able to key in the description of the object therefore there might be the same word because is enter by different user. So i will create a textbox using query whereby when i search for the word "loud" and objects containing loud will appear but first i have to connect to C sharp take out my description and count the number of loud and rank the object that contain the most loud at the top.

But the problem i am facing now is there are so many rows and i couldnt read data by rows. So i need asssitance in this. Thanks so much

thanks people for the help. i managed to use delimit and count the number of words per records but the problem i am facing now will be creating one more column in my database and put it back into access. Do anyone has any idea on how am i suppose to do that?

sorry before adding back to access i have one more problem. How am i suppose to only count the words that the user entered rather than the whole string of words.

You're asking too many broad questions without providing enough information to answer your question. How can you distinguish which records a user keyed versus ones that were existing in the database? Do you allow user editing on a data grid showing the data or do you have a text box on a form where they can key data? These are all very important pieces of information in order to answer your questions.


The user will be able to key in the description of the object therefore there might be the same word because is enter by different user. So i will create a textbox using query whereby when i search for the word "loud" and objects containing loud will appear but first i have to connect to C sharp take out my description and count the number of loud and rank the object that contain the most loud at the top.

Sorry I missed this in my last post but I still have a question. Is this textbox databound to a grid row or is it a single text box used to key data against all rows? If its databound you will want to work with the in-memory data, if its unbound you will obviously use the .text property.

hmmm actually my search textbox everything is in my access program. In my C sharp, i only called the database put each word in a array and for now i wan to do a wordcount on the words which user choose under access.

so for now, i am using
if(keyword.Equals(userkeyin)

keyword will be the array containing all my words but i do not know what to put in the userkeyin part because my textbox is in access. so what can i do next?

hmmm actually my search textbox everything is in my access program. In my C sharp, i only called the database put each word in a array and for now i wan to do a wordcount on the words which user choose under access.

so for now, i am using
if(keyword.Equals(userkeyin)

keyword will be the array containing all my words but i do not know what to put in the userkeyin part because my textbox is in access. so what can i do next?

Get a file sharing account like http://www.2shared.com/ and upload your project and database because with each post it makes less sense. Now i'm envisioning that you have a textbox with the contents of your entire access database (all rows + all columns, i'm assuming a multi line) but in the earlier threads you were having trouble reading all of the access data so that obviously cannot be the case.

Upload your files somewhere so we can help you because these questions do not make any sense.

thanks anyway i managed to solve it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.