Hi,
My application is in VS2008 coded in Vb.net.
I have a datagridView which is getting populated from the Database.I has RegNo,RollNo,Name etc fields.The data in the Name column of database is coming from 3 columns of a certain table from database.
This is how im concatinating it and displaying in datagrid.

SELECT StudAllocDtls.RegNo,StudAllocDtls.RollNo,AdmittedStudents.SurName + ' ' + AdmittedStudents.FirstName + ' ' + AdmittedStudents.LastName

.
My issue is i want to save this data in some other table which also has Surname,FirstName,LastName columns in the database.
Im not able to split the column data present in datagridview cell into three fields.
For Example:Name column in datagridview is having Name : Sachin Ramesh Tendulkar.
I want to divide this string into three like : Sachin for Surname,Ramesh for First Name,Tendulkar for LastName.
This is my query:

"INSERT INTO SmsSetting(Regno,RollNo,SurName + ' ' + FirstName + ' ' + LastName,MobileNo,              FathMobile,MothMobile)VALUES('" & DGVStudRecord.Item(0, i).Value.ToString & "','" & DGVStudRecord.Item(1, i).Value.ToString & "','" & DGVStudRecord.Item(2, i).Value.ToString & "','" & DGVStudRecord.Item(3, i).Value.ToString & "','" & DGVStudRecord.Item(4, i).Value.ToString & "','" & DGVStudRecord.Item(5, i) & "'

Please correct me where can i fetch

If I get your correctly, you populate DGV with some values: name, surname, and another surname - all in one cell. Now you would like to split this cell into name, and lastnames?
If Iam correct, Split it by whitespace:

Dim data As String() = dataGridView1.Rows(0).Cells(0).Value.ToString().Split(" "C)
'data array now has all name and lastname(s).

Use array data in your code.

In get values of array you need to see if any extra white space which doesnt have any value.

Yes it is showing white spaces,an issue for taking Index number from array .

You can get the value without the extra white spaces with the .trim method.

Dim Str as String() = Datagridview.Item(0,0).Value.ToString.Trim.Split(" ")

Now you should have an array with 3 positions if the value has name, surname and last name.
Also you can check the length of the resulting array with

Str.Lenght

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.