Re: DBnull in dataTable.Columns.Add()
- From: "Miha Markic [MVP C#]" <miha at rthand com>
- Date: Mon, 14 Aug 2006 22:13:00 +0200
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 [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:eqvG%23I7vGHA.2436@xxxxxxxxxxxxxxxxxxxxxxx
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" <00@xxxxx> schreef in bericht
news:44e08d70$0$751$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxxxxx
Well it compiles without a problem.
"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:%23J0Y306vGHA.2232@xxxxxxxxxxxxxxxxxxxxxxx
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/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassmaxlengthtopic.asp
Although I expect more trouble than benefit from that.
I hope this helps,
Cor
"Adrian" <00@xxxxx> schreef in bericht
news:44e08420$0$724$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxxxxx
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[i].ToString();
}
}
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:e4oC245vGHA.4444@xxxxxxxxxxxxxxxxxxxxxxx
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" <00@xxxxx> wrote in message
news:44e06832$0$710$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxxxxx
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
news:%23WNejX5vGHA.724@xxxxxxxxxxxxxxxxxxxxxxx
DataColumn col =dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"))
;
col.AllowDBNull = false; // or true;dataTable.Columns.Add("columnName",System.Type.GetType("System.[whatever]"),
--
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" <00@xxxxx> wrote in message
news:44e04d15$0$726$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxxxxx
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
news:uUDccI4vGHA.976@xxxxxxxxxxxxxxxxxxxxxxx
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" <00@xxxxx> wrote in message
news:44e034c4$0$722$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxxxxx
Re the code line:
syntax?;
(I am working in c#)
Can one add that null is / is not allowed? And, if so. what is
the
Adrian.
.
- References:
- Re: DBnull in dataTable.Columns.Add()
- From: Miha Markic [MVP C#]
- Re: DBnull in dataTable.Columns.Add()
- From: Miha Markic [MVP C#]
- Re: DBnull in dataTable.Columns.Add()
- From: Miha Markic [MVP C#]
- Re: DBnull in dataTable.Columns.Add()
- From: Cor Ligthert [MVP]
- Re: DBnull in dataTable.Columns.Add()
- From: Cor Ligthert [MVP]
- Re: DBnull in dataTable.Columns.Add()
- Prev by Date: Re: Retrieving primary key of newly added record
- Next by Date: Re: Using queries in a table adaptor?
- Previous by thread: Re: DBnull in dataTable.Columns.Add()
- Next by thread: creating a folder
- Index(es):
Relevant Pages
|