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.