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

  • Thread starter Thread starter Bill
  • Start date Start date
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?
 
Just declare a new datarow =

DataRow dro = TypedDataSet.TableName.NewRow();
dro[0] = "WhateverYOuWantFirstColumnToBe";
dro[1] = "Same";
TypeDataSet.TableName.Rows.Add(dro);
 
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?
 
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
 
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
 
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?
 
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
 
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?
 
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?
 
Back
Top