Question

The end goal is to create a database that contains all our automated tests and the date they were added. We are using reflection on the DLLs to obtain each project, class and test name. We save it into a datatable. From there, we want to save it in a database. We have an additional field in the database with a default sql value of GetDate(). If I manually insert values into SQL, the date field is populated for me. Our code that gets the attributes from reflection works and we are happy with the dataTable.

What I was hoping to have happen is that the C# exe could be run daily and any new tests would them be added into SQL and the existing tests, along with the time value generated by sql would remain the same. I thought the "update" would be good to use as I only want to add new tests.

I fill my datatable as follows

DataRow workRow = dt.NewRow();
workRow["Project"] = testProject.GetName().Name;
workRow["TestName"] = method.Name;
workRow["Class"] = method.DeclaringType.Name;
dt.Rows.Add(workRow);

I attempt to update the database like this

SqlConnection cn = new SqlConnection("Data Source=SomeSqlServer;Initial    Catalog=TestTracking;Integrated Security=SSPI;Network Library=DBNMPNTW;");
SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * from Tests", cn);;
SqlCommandBuilder cmdb = new SqlCommandBuilder(dataAdapter);
dataAdapter.Update(ds,"Tests");

This returns an invalid operation exception because I am missing DataColumn Date in the dataTable 'tests' for the SourceColumn Date. This is true. I want to ignore the date and let SQL fill it in.

Does anyone have ideas on how to solve this, or to make it better by using a different appoach?

Was it helpful?

Solution

You could change your SELECT string to select only Project, TestName, and Class from Tests. You could also create a stored procedure that updates your Tests table given your 3 parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top