DBnull in dataTable.Columns.Add()

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Re the code line:

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the syntax?

Adrian.
 
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



Miha Markic said:
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Adrian said:
Re the code line:

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the syntax?

Adrian.
 
DataColumn col =
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"));
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


Adrian said:
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



Miha Markic said:
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Adrian said:
Re the code line:

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the syntax?

Adrian.
 
This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

Miha Markic said:
DataColumn col =
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


Adrian said:
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



Miha Markic said:
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the syntax?

Adrian.
 
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Adrian said:
This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

Miha Markic said:
DataColumn col =
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


Adrian said:
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:


dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the
syntax?

Adrian.
 
at dt.Columns.Add("ForeName", System.Type.GetType("System.nvarchar(35)"))
Error message: 'dataType' argument cannot be null. Parameter name: dataType
What you suggest isn't working

This is all the code of the coding example:

using(DataSet ds = new DataSet())
{
DataTable dt = ds.Tables.Add("Addresses");
dt.Columns.Add("ForeName", System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("LastName", System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.nvarchar(35)"));
object[] one = { "John", "Johnson", "1234567890" };
object[] two = { "Fred", "Fredson", "1234567890" };
object[] three = { "James", "Jameson", "1234567890" };
dt.Rows.Add(one);
dt.Rows.Add(two);
dt.Rows.Add(three);
string show = string.Empty;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Rows.Count; i++)
show += row.ItemArray.ToString();
}
}



Miha Markic said:
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Adrian said:
This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

Miha Markic said:
DataColumn col =
dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:


dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the
syntax?

Adrian.
 
Adrian,

Why are you using "System.nvarchar(35)".
I have nowhere seen that this is possible.

The sentence can be as Miha showed and than use the maxlength to limit it.
http://msdn.microsoft.com/library/d...rfsystemdatadatacolumnclassmaxlengthtopic.asp

Although I expect more trouble than benefit from that.

I hope this helps,

Cor



Adrian said:
at dt.Columns.Add("ForeName", System.Type.GetType("System.nvarchar(35)"))
Error message: 'dataType' argument cannot be null. Parameter name:
dataType
What you suggest isn't working

This is all the code of the coding example:

using(DataSet ds = new DataSet())
{
DataTable dt = ds.Tables.Add("Addresses");
dt.Columns.Add("ForeName", System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("LastName", System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.nvarchar(35)"));
object[] one = { "John", "Johnson", "1234567890" };
object[] two = { "Fred", "Fredson", "1234567890" };
object[] three = { "James", "Jameson", "1234567890" };
dt.Rows.Add(one);
dt.Rows.Add(two);
dt.Rows.Add(three);
string show = string.Empty;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Rows.Count; i++)
show += row.ItemArray.ToString();
}
}



Miha Markic said:
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Adrian said:
This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
DataColumn col =

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is the
syntax?

Adrian.
 
Well it compiles without a problem.


Cor Ligthert said:
Adrian,

Why are you using "System.nvarchar(35)".
I have nowhere seen that this is possible.

The sentence can be as Miha showed and than use the maxlength to limit it.
http://msdn.microsoft.com/library/d...rfsystemdatadatacolumnclassmaxlengthtopic.asp

Although I expect more trouble than benefit from that.

I hope this helps,

Cor



Adrian said:
at dt.Columns.Add("ForeName", System.Type.GetType("System.nvarchar(35)"))
Error message: 'dataType' argument cannot be null. Parameter name:
dataType
What you suggest isn't working

This is all the code of the coding example:

using(DataSet ds = new DataSet())
{
DataTable dt = ds.Tables.Add("Addresses");
dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("LastName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.nvarchar(35)"));
object[] one = { "John", "Johnson", "1234567890" };
object[] two = { "Fred", "Fredson", "1234567890" };
object[] three = { "James", "Jameson", "1234567890" };
dt.Rows.Add(one);
dt.Rows.Add(two);
dt.Rows.Add(three);
string show = string.Empty;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Rows.Count; i++)
show += row.ItemArray.ToString();
}
}



Miha Markic said:
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
DataColumn col =

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is
the
syntax?

Adrian.

 
Adrian,

Not so strange because it is a string that you are supporting, which is not
evalutated in design time.
Try to do it in the sample as Miha showed and you will almost for sure get
an error.

Cor

Adrian said:
Well it compiles without a problem.


Cor Ligthert said:
Adrian,

Why are you using "System.nvarchar(35)".
I have nowhere seen that this is possible.

The sentence can be as Miha showed and than use the maxlength to limit
it.
http://msdn.microsoft.com/library/d...rfsystemdatadatacolumnclassmaxlengthtopic.asp

Although I expect more trouble than benefit from that.

I hope this helps,

Cor



Adrian said:
at dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"))
Error message: 'dataType' argument cannot be null. Parameter name:
dataType
What you suggest isn't working

This is all the code of the coding example:

using(DataSet ds = new DataSet())
{
DataTable dt = ds.Tables.Add("Addresses");
dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("LastName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.nvarchar(35)"));
object[] one = { "John", "Johnson", "1234567890" };
object[] two = { "Fred", "Fredson", "1234567890" };
object[] three = { "James", "Jameson", "1234567890" };
dt.Rows.Add(one);
dt.Rows.Add(two);
dt.Rows.Add(three);
string show = string.Empty;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Rows.Count; i++)
show += row.ItemArray.ToString();
}
}



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
DataColumn col =

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is
the
syntax?

Adrian.


 
Yep, and Adrian, valid types are .net types and not database types.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Cor Ligthert said:
Adrian,

Not so strange because it is a string that you are supporting, which is
not evalutated in design time.
Try to do it in the sample as Miha showed and you will almost for sure get
an error.

Cor

Adrian said:
Well it compiles without a problem.


Cor Ligthert said:
Adrian,

Why are you using "System.nvarchar(35)".
I have nowhere seen that this is possible.

The sentence can be as Miha showed and than use the maxlength to limit
it.
http://msdn.microsoft.com/library/d...rfsystemdatadatacolumnclassmaxlengthtopic.asp

Although I expect more trouble than benefit from that.

I hope this helps,

Cor



"Adrian" <[email protected]> schreef in bericht
at dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"))
Error message: 'dataType' argument cannot be null. Parameter name:
dataType
What you suggest isn't working

This is all the code of the coding example:

using(DataSet ds = new DataSet())
{
DataTable dt = ds.Tables.Add("Addresses");
dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("LastName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.nvarchar(35)"));
object[] one = { "John", "Johnson", "1234567890" };
object[] two = { "Fred", "Fredson", "1234567890" };
object[] three = { "James", "Jameson", "1234567890" };
dt.Rows.Add(one);
dt.Rows.Add(two);
dt.Rows.Add(three);
string show = string.Empty;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Rows.Count; i++)
show += row.ItemArray.ToString();
}
}



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
DataColumn col =

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is
the
syntax?

Adrian.


 
I see that you are right. Using "String" solves the problem.
Thank you,
Adrian.


Miha Markic said:
Yep, and Adrian, valid types are .net types and not database types.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Cor Ligthert said:
Adrian,

Not so strange because it is a string that you are supporting, which is
not evalutated in design time.
Try to do it in the sample as Miha showed and you will almost for sure
get an error.

Cor

Adrian said:
Well it compiles without a problem.


Adrian,

Why are you using "System.nvarchar(35)".
I have nowhere seen that this is possible.

The sentence can be as Miha showed and than use the maxlength to limit
it.
http://msdn.microsoft.com/library/d...rfsystemdatadatacolumnclassmaxlengthtopic.asp

Although I expect more trouble than benefit from that.

I hope this helps,

Cor



"Adrian" <[email protected]> schreef in bericht
at dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"))
Error message: 'dataType' argument cannot be null. Parameter name:
dataType
What you suggest isn't working

This is all the code of the coding example:

using(DataSet ds = new DataSet())
{
DataTable dt = ds.Tables.Add("Addresses");
dt.Columns.Add("ForeName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("LastName",
System.Type.GetType("System.nvarchar(35)"));
dt.Columns.Add("TelephoneNumber",
System.Type.GetType("System.nvarchar(35)"));
object[] one = { "John", "Johnson", "1234567890" };
object[] two = { "Fred", "Fredson", "1234567890" };
object[] three = { "James", "Jameson", "1234567890" };
dt.Rows.Add(one);
dt.Rows.Add(two);
dt.Rows.Add(three);
string show = string.Empty;
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Rows.Count; i++)
show += row.ItemArray.ToString();
}
}



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Did you really try to use System.[whatever] type?
DataTable table = new DataTable("Test");

DataColumn col = table.Columns.Add("columnName", typeof(string));

col.AllowDBNull = false;


--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

This sitll produces the error
'dataType' argument cannot be null. Parameter name: data Type

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
DataColumn col =

dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
DataColumn.*** )
*** two options: Equals and Referece Equals.

Could you please tell me what the code sould be and where?
I have searched MSDN and cannot find the answer to my query.

Adrian.



"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Set DataColumn.AllowDBNull property after you created the
column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Re the code line:



dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;

(I am working in c#)

Can one add that null is / is not allowed? And, if so. what is
the
syntax?

Adrian.


 
Back
Top