How to set width of a p:column in a p:dataTable in PrimeFaces 3.0?

In PrimeFaces 3.0, that style get applied on the generated inner <div> of the table cell, not on the <td> as you (and I) would expect. The following example should work out for you: <p:dataTable styleClass=”myTable”> with .myTable td:nth-child(1) { width: 20px; } In PrimeFaces 3.5 and above, it should work exactly the way you … Read more

Change Row background color based on cell value DataTable

OK I was able to solve this myself: $(document).ready(function() { $(‘#tid_css’).DataTable({ “iDisplayLength”: 100, “bFilter”: false, “aaSorting”: [ [2, “desc”] ], “fnRowCallback”: function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { if (aData[2] == “5”) { $(‘td’, nRow).css(‘background-color’, ‘Red’); } else if (aData[2] == “4”) { $(‘td’, nRow).css(‘background-color’, ‘Orange’); } } }); })

How do I create a DataTable, then add rows to it?

Here’s the code: DataTable dt = new DataTable(); dt.Clear(); dt.Columns.Add(“Name”); dt.Columns.Add(“Marks”); DataRow _ravi = dt.NewRow(); _ravi[“Name”] = “ravi”; _ravi[“Marks”] = “500”; dt.Rows.Add(_ravi); To see the structure, or rather I’d rephrase it as schema, you can export it to an XML file by doing the following. To export only the schema/structure, do: dt.WriteXMLSchema(“dtSchemaOrStructure.xml”); Additionally, you can … Read more

Print Contents Of A DataTable

you can try this code : foreach(DataRow dataRow in Table.Rows) { foreach(var item in dataRow.ItemArray) { Console.WriteLine(item); } } Update 1 DataTable Table = new DataTable(“TestTable”); using(SqlCommand _cmd = new SqlCommand(queryStatement, _con)) { SqlDataAdapter _dap = new SqlDataAdapter(_cmd); _con.Open(); _dap.Fill(Table); _con.Close(); } Console.WriteLine(Table.Rows.Count); foreach(DataRow dataRow in Table.Rows) { foreach(var item in dataRow.ItemArray) { Console.WriteLine(item); } … Read more

Creating a SQL Server table from a C# datatable

public static string CreateTABLE(string tableName, DataTable table) { string sqlsc; sqlsc = “CREATE TABLE ” + tableName + “(“; for (int i = 0; i < table.Columns.Count; i++) { sqlsc += “\n [” + table.Columns[i].ColumnName + “] “; string columnType = table.Columns[i].DataType.ToString(); switch (columnType) { case “System.Int32″: sqlsc += ” int “; break; case “System.Int64”: … Read more

Transform a DataTable into Dictionary C#

The generic method ToDictionary has 3 parameters. You left one off, so it doesn’t know what to do. If you want to specify all of the parameters, it would be <DataRow, string, object>. internal Dictionary<string,object> GetDict(DataTable dt) { return dt.AsEnumerable() .ToDictionary<DataRow, string, object>(row => row.Field<string>(0), row => row.Field<object>(1)); } Of course, if you leave them … Read more

Inner join of DataTables in C#

If you are allowed to use LINQ, take a look at the following example. It creates two DataTables with integer columns, fills them with some records, join them using LINQ query and outputs them to Console. DataTable dt1 = new DataTable(); dt1.Columns.Add(“CustID”, typeof(int)); dt1.Columns.Add(“ColX”, typeof(int)); dt1.Columns.Add(“ColY”, typeof(int)); DataTable dt2 = new DataTable(); dt2.Columns.Add(“CustID”, typeof(int)); dt2.Columns.Add(“ColZ”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)