How do I programattically add a new row of data to a Typed DataSet?

B

Bill

I am able to fill DataSet tables in a typed DataSet from SQL Server, but now
have a situation where I need to load positionally delimited text, but am
not quite sure of the syntax for this. Do I create a new datatable DataRow
from the typed DataTable, populate it with data, and then add the row... or
what?
 
W

William Ryan eMVP

Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
 
B

Brad Williams

It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


William Ryan eMVP said:
Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
Bill said:
I am able to fill DataSet tables in a typed DataSet from SQL Server, but now
have a situation where I need to load positionally delimited text, but am
not quite sure of the syntax for this. Do I create a new datatable DataRow
from the typed DataTable, populate it with data, and then add the row... or
what?
 
B

Bill

Ahhh. This is a cool solution.

Thanks.

Brad Williams said:
It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


William Ryan eMVP said:
Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
Bill said:
I am able to fill DataSet tables in a typed DataSet from SQL Server,
but
now
have a situation where I need to load positionally delimited text, but am
not quite sure of the syntax for this. Do I create a new datatable DataRow
from the typed DataTable, populate it with data, and then add the
row...
or
 
B

Bill

Hmmmm.... actually, I'm lost on the dacRole, etc. What is that?

Brad Williams said:
It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


William Ryan eMVP said:
Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
Bill said:
I am able to fill DataSet tables in a typed DataSet from SQL Server,
but
now
have a situation where I need to load positionally delimited text, but am
not quite sure of the syntax for this. Do I create a new datatable DataRow
from the typed DataTable, populate it with data, and then add the
row...
or
 
B

Brad Williams

Sorry that's my specific stuff I didn't strip out. Just use your typed data
set variable. This isn't very readable but more accurate:

MYDSTYPE.MYTABLEROW dr = MYDSVAR.MYTABLE.NewMYTABLERow();

Brad Williams


Bill said:
Hmmmm.... actually, I'm lost on the dacRole, etc. What is that?

Brad Williams said:
It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


William Ryan eMVP said:
Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
I am able to fill DataSet tables in a typed DataSet from SQL Server, but
now
have a situation where I need to load positionally delimited text,
but
am
not quite sure of the syntax for this. Do I create a new datatable DataRow
from the typed DataTable, populate it with data, and then add the row...
or
what?
 
W

William Ryan eMVP

Good point. I've got canned text i add in for this question and didn't do
my editing correctly. Using typed methodology is absolutely better.

Thanks again,

Bill
Brad Williams said:
It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


William Ryan eMVP said:
Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
Bill said:
I am able to fill DataSet tables in a typed DataSet from SQL Server,
but
now
have a situation where I need to load positionally delimited text, but am
not quite sure of the syntax for this. Do I create a new datatable DataRow
from the typed DataTable, populate it with data, and then add the
row...
or
 
B

Bill

Intellisense is only showing "Equals" and "ReferenceEquals" for the Type.
I.e., in your example it would be MYDSTYPE.Equals or
MYDSTYPE.ReferenceEquals.

Am I missing something?

Brad Williams said:
Sorry that's my specific stuff I didn't strip out. Just use your typed data
set variable. This isn't very readable but more accurate:

MYDSTYPE.MYTABLEROW dr = MYDSVAR.MYTABLE.NewMYTABLERow();

Brad Williams


Bill said:
Hmmmm.... actually, I'm lost on the dacRole, etc. What is that?

Brad Williams said:
It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
I am able to fill DataSet tables in a typed DataSet from SQL
Server,
but
now
have a situation where I need to load positionally delimited text, but
am
not quite sure of the syntax for this. Do I create a new datatable
DataRow
from the typed DataTable, populate it with data, and then add the row...
or
what?
 
B

Bill

Never mind... it's working now.

Great solution.

Bill said:
Intellisense is only showing "Equals" and "ReferenceEquals" for the Type.
I.e., in your example it would be MYDSTYPE.Equals or
MYDSTYPE.ReferenceEquals.

Am I missing something?

Brad Williams said:
Sorry that's my specific stuff I didn't strip out. Just use your typed data
set variable. This isn't very readable but more accurate:

MYDSTYPE.MYTABLEROW dr = MYDSVAR.MYTABLE.NewMYTABLERow();

Brad Williams


Bill said:
Hmmmm.... actually, I'm lost on the dacRole, etc. What is that?

It's better to use the typed methods and properties, eg for table named
"sRole" in typed dataset:

UserDS.sRoleRow dr = this.dacRole.UserDataSet.sRole.NewsRoleRow();
dr.Name = "";
dr.Description = "";
userDataSet.sRole.AddsRoleRow(dr);

Brad Williams


Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
I am able to fill DataSet tables in a typed DataSet from SQL Server,
but
now
have a situation where I need to load positionally delimited
text,
but
am
not quite sure of the syntax for this. Do I create a new datatable
DataRow
from the typed DataTable, populate it with data, and then add the
row...
or
what?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top