Bind Crystal Reports with Dataset - c#

I am having a form where I am updating data in my gridview and that updated gridview I want to save in one of the table on Save_Button_click; after that i want to generate report(crystal) for that sorted and updated data; there I got stuck ; Thanks in advance!
here is my query:
string StrAsset = "select * from tbl_Pre_Y1_Bus1,tbl_Pre_Y1_Bus_Master1_temp where tbl_Pre_Y1_Bus1.id='" + id + "' and tbl_Pre_Y1_Bus_Master1_temp.ID='" + ID + "')";
My Code:
{
dt.Columns.Add(new System.Data.DataColumn("id", typeof(int)));
dt.Columns.Add(new System.Data.DataColumn("PartNo", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("ChallanDate", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("ChallanNo", typeof(int)));
dt.Columns.Add(new System.Data.DataColumn("sup_remark", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("sup_status", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("TMl_remark", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Tml_status", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Date_supp", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Sup_ins_name", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("date_insp", typeof(string)));
dt.Columns.Add(new System.Data.DataColumn("Inspectorname", typeof(string)));
}
for (int i = 0; i < DSAsset.Tables[0].Rows.Count; i++)
{
dr = dt.NewRow();
dr[12] = DSAsset.Tables[0].Rows[i]["sup_remark"].ToString();
dr[13] = DSAsset.Tables[0].Rows[i]["sup_status"].ToString();
dr[14] = DSAsset.Tables[0].Rows[i]["TMl_remark"].ToString();
dr[15] = DSAsset.Tables[0].Rows[i]["Tml_status"].ToString();
dr[16] = DSAsset.Tables[0].Rows[i]["Date_supp"].ToString();
dr[17] = DSAsset.Tables[0].Rows[i]["Sup_ins_name"].ToString();
dr[18] = DSAsset.Tables[0].Rows[i]["date_insp"].ToString();
dr[19] = DSAsset.Tables[0].Rows[i]["Inspectorname"].ToString();
dt.Rows.Add(dr);
dt.AcceptChanges();
}
aspx code
<CR:CrystalReportViewer ID="CrystalReportViewer1" HasCrystalLogo="False" runat="server"
AutoDataBind="true" ReportSourceID="CrystalReportSource1" DisplayGroupTree="False"
EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="Dispatch.rpt">
</Report>
</CR:CrystalReportSource>
how to resolve this problem:
it is not generating report.

Related

DataRow.ItemArray does not have values and is empty

my DataRow object is emtpy no matter how I try to initialize it. Here is the source code:
private DataTable ReadFileIntoDb(MemoryStream file)
{
file.Position = 0;
var sr = new StreamReader(file,Encoding.GetEncoding(1251),true);
var dt = new DataTable();
Console.WriteLine("datatable success");
dt.Columns.Add(new DataColumn("description", typeof(String)));
dt.Columns.Add(new DataColumn("code", typeof(String)));
dt.Columns.Add(new DataColumn("cardnumber", typeof(String)));
dt.Columns.Add(new DataColumn("costcentrecode", typeof(int)));
dt.Columns.Add(new DataColumn("costcentre", typeof(String)));
dt.Columns.Add(new DataColumn("article_description", typeof(String)));
dt.Columns.Add(new DataColumn("trans_date", typeof(DateTime)));
dt.Columns.Add(new DataColumn("article_price", typeof(Double)));
dt.Columns.Add(new DataColumn("article_quantity", typeof(Double)));
dt.Columns.Add(new DataColumn("netto", typeof(Double)));
dt.Columns.Add(new DataColumn("brutto", typeof(Double)));
dt.Columns.Add(new DataColumn("mwst", typeof(Double)));
dt.Columns.Add(new DataColumn("beleg", typeof(Double)));
dt.Columns.Add(new DataColumn("oberverkaufsgruppe", typeof(int)));
dt.Columns.Add(new DataColumn("house", typeof(String)));
dt.Columns.Add(new DataColumn("id", typeof(String)));
//1. row gets skipped
string line = sr.ReadLine();
Console.WriteLine("line contains:" + line);
line = sr.ReadLine();
do
{
string[] itemArray = line.Split(';');
DataRow row = dt.NewRow();
row.ItemArray = itemArray; //doesnt work and throws ArgumentException
itemArray.CopyTo(row.ItemArray, 0); //doesnt work either
for (int i = 0; i < 14; i++) //also doesnt work and leaves it empty
{
row.ItemArray[i] = itemArray[i];
Console.WriteLine(row.ItemArray[i]);
}
row["id"] = Guid.NewGuid().ToString();
row["house"] = "";
dt.Rows.Add(row);
line = sr.ReadLine();
} while (!string.IsNullOrEmpty(line));
ReadFileIntoDb gets the content of a csv file as a parameter. Right now i reduced the csv content to only two lines which of one is just the header. The content looks like this and gets parsed successfully into var sr:
Bewohner;1102284;1102284;42600;ASG ROT;Menü (Inklusivleistung);01.07.2022;0;1;;;;;2000003
As you can see this file contains 14 elements, some of which are empty. My DataTable also contains 14 columns and 2 additional which I set inside the code however and their values do not come from the csv.
After performing the database operations my tables remain empty because I believe that row.ItemArray always remains empty so nothing gets added to the database. But I don't understand why it stays empty and why i get a ArgumentException. The source array itemArray is NOT empty and is also of length 14. So why does the exception get thrown if row.ItemArray is bigger in length? It has 16.
Look into this ,I change the input string a bit
The line i added is
for (int i = 0; i < itemArray.Length; i++)
{
if (string.IsNullOrWhiteSpace(itemArray[i]))
{
itemArray[i] = null;
}
}
for replacing the empty values as null in the given input , without this i got the error
Unhandled exception. System.ArgumentException: Input string was not in a correct format.Couldn't store <> in netto Column. Expected type is Double.
---> System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.String.System.IConvertible.ToDouble(IFormatProvider provider)
at System.Data.Common.DoubleStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)
--- End of inner exception stack trace ---
at System.Data.DataColumn.set_Item(Int32 record, Object value)
at System.Data.DataRow.set_ItemArray(Object[] value)
at Program.Main()
Command terminated by signal 6
using System;
using System.Data;
public class Program
{
public static void Main()
{
string sp="Bewohner;1102284;1102284;42600;ASG ROT;Menü (Inklusivleistung);01.07.2022;0;1;;;;;2000003^Bewohner2;11022842;11022824;426200;ASG2 ROT;Menü (Inklusivleistung);01.07.2022;0;1;;;;;2000004";
var dt = new DataTable();
Console.WriteLine("datatable success");
dt.Columns.Add(new DataColumn("description", typeof(String)));
dt.Columns.Add(new DataColumn("code", typeof(String)));
dt.Columns.Add(new DataColumn("cardnumber", typeof(String)));
dt.Columns.Add(new DataColumn("costcentrecode", typeof(int)));
dt.Columns.Add(new DataColumn("costcentre", typeof(String)));
dt.Columns.Add(new DataColumn("article_description", typeof(String)));
dt.Columns.Add(new DataColumn("trans_date", typeof(DateTime)));
dt.Columns.Add(new DataColumn("article_price", typeof(Double)));
dt.Columns.Add(new DataColumn("article_quantity", typeof(Double)));
dt.Columns.Add(new DataColumn("netto", typeof(Double)));
dt.Columns.Add(new DataColumn("brutto", typeof(Double)));
dt.Columns.Add(new DataColumn("mwst", typeof(Double)));
dt.Columns.Add(new DataColumn("beleg", typeof(Double)));
dt.Columns.Add(new DataColumn("oberverkaufsgruppe", typeof(int)));
dt.Columns.Add(new DataColumn("house", typeof(String)));
dt.Columns.Add(new DataColumn("id", typeof(String)));
string[] mainarray = sp.Split('^');
for(int a=0;a<mainarray.Length;a++)
{
string[] itemArray = mainarray[a].Split(';');
DataRow row = dt.NewRow();
for (int i = 0; i < itemArray.Length; i++)
{
if (string.IsNullOrWhiteSpace(itemArray[i]))
{
itemArray[i] = null;
}
}
row.ItemArray = itemArray; //doesnt work and throws ArgumentException
itemArray.CopyTo(row.ItemArray, 0); //doesnt work either
for (int i = 0; i < 14; i++) //also doesnt work and leaves it empty
{
row.ItemArray[i] = itemArray[i];
//Console.WriteLine(row.ItemArray[i]);
}
row["id"] = Guid.NewGuid().ToString();
row["house"] = "";
dt.Rows.Add(row);
}
foreach(DataRow dataRow in dt.Rows)
{var ix = 0;
foreach(var item in dataRow.ItemArray)
{
Console.WriteLine(ix+"-----"+item);
ix++;
}
}
}
}
OUTPUT :
datatable success
0-----Bewohner
1-----1102284
2-----1102284
3-----42600
4-----ASG ROT
5-----Menü (Inklusivleistung)
6-----01/07/2022 00:00:00
7-----0
8-----1
9-----
10-----
11-----
12-----
13-----2000003
14-----
15-----ccf0a446-610e-4396-896d-7e8c4a43f729
0-----Bewohner2
1-----11022842
2-----11022824
3-----426200
4-----ASG2 ROT
5-----Menü (Inklusivleistung)
6-----01/07/2022 00:00:00
7-----0
8-----1
9-----
10-----
11-----
12-----
13-----2000004
14-----
15-----0c9cb9b1-8640-4626-8790-0d80fad9d8da

Adding rows in data table in c#

I have created a data table in my Application start method and I am trying to add rows to this data table from my session start method. When I try to add rows, it gives an error on the data table that
the name does not exists in the current context.
I am a beginner to programming. Any help is appreciated.
Here is my code:
// application begins
void Application_Start(Object s, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("session_id", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("username", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("login_time", System.Type.GetType("System.DateTime")));
dt.Columns.Add(new DataColumn("ip_address", System.Type.GetType("System.String")));
Application["visitorTable"] = dt;
}
// browser's first visit to the page, (session starts)
void Session_Start(Object s, EventArgs e)
{
{
Application.Lock();
DataRow dr = dt.NewRow();
dr["session_id"] = (System.String)HttpContext.Current.Session.SessionID; // session id
dr["ip_address"] = Request.ServerVariables["SERVER_NAME"]; //ip-address
dt.Rows.Add(dr);
dt = (Database)Application["visitorTable"];
Application["visitorTable"] = dt;
Application.UnLock();
}
}
Check this
Dynamically create DataTable and bind to GridView in ASP.Net
it might be help you
DataTable dt;
void Application_Start(Object s, EventArgs e)
{
dt= new DataTable();
dt.Columns.Add(new DataColumn("session_id", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("username", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("login_time", System.Type.GetType("System.DateTime")));
dt.Columns.Add(new DataColumn("ip_address", System.Type.GetType("System.String")));
Application["visitorTable"] = dt;
}
You should specify the table name when creating a new DataTabe...
DataTable dt = new DataTable("VisitorTable");
dt.Columns.Add(new DataColumn("session_id", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("username", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("login_time", System.Type.GetType("System.DateTime")));
dt.Columns.Add(new DataColumn("ip_address", System.Type.GetType("System.String")));
Application["visitorTable"] = dt;
// you create it like this
Application["visitorTable"] = dt;
// and you read it like this
dt = (Database)Application["VisitorTable"];
Notice the issue?
Also you don't need to rely on reflection to get a type's description, a simple compile time typeof(string) and typeof(DateTime) will take care of it.
when your are executing following code
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("session_id", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("username", System.Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("login_time", System.Type.GetType("System.DateTime")));
dt.Columns.Add(new DataColumn("ip_address", System.Type.GetType("System.String")));
have you checked whether your dt added with column name specified ?
or dt is generated with columns Column1,colum2,column3
if those are generated with Column1,colum2,column3 ths why you ll be facing above error ,
rename column with your name of dt

value getting changed during SqlBulkCopy

I am trying to upload some data from csv file to sql server using SqlBulkCopy
The problem here is that the values get changed automatically
eg 0.9824 becomes 0.982400000095367
Here is the code that I am using
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(strConnectionString, SqlBulkCopyOptions.FireTriggers))
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("dt", typeof(DateTime)));
dt.Columns.Add(new DataColumn("wreb", typeof(string)));
dt.Columns.Add(new DataColumn("zid", typeof(int)));
dt.Columns.Add(new DataColumn("zone_name", typeof(string)));
dt.Columns.Add(new DataColumn("region", typeof(string)));
dt.Columns.Add(new DataColumn("iloss", typeof(float)));
dt.Columns.Add(new DataColumn("dloss", typeof(float)));
for (int i = 0; i < DataDS.Tables[0].Rows.Count; i++)
{
DataRow myDr = dt.NewRow();
myDr["dt"] = DateTime.ParseExact(DataDS.Tables[0].Rows[i]["dt"].ToString(), "d/M/yyyy", null);
myDr["wreb"] = DataDS.Tables[0].Rows[i]["wreb"].ToString();
myDr["zid"] = DataDS.Tables[0].Rows[i]["zid"].ToString();
myDr["zone_name"] = DataDS.Tables[0].Rows[i]["zone_name"].ToString();
myDr["region"] = DataDS.Tables[0].Rows[i]["region"].ToString();
myDr["iloss"] = DataDS.Tables[0].Rows[i]["iloss"].ToString();
myDr["dloss"] = DataDS.Tables[0].Rows[i]["dloss"].ToString();
dt.Rows.Add(myDr);
myDr = null;
}
bulkCopy.BulkCopyTimeout = 0;
bulkCopy.ColumnMappings.Add("dt", "Zdate");
bulkCopy.ColumnMappings.Add("wreb", "Entity");
bulkCopy.ColumnMappings.Add("zid", "ZoneID");
bulkCopy.ColumnMappings.Add("zone_name", "Zone_Name");
bulkCopy.ColumnMappings.Add("region", "region");
bulkCopy.ColumnMappings.Add("iloss", "iloss");
bulkCopy.ColumnMappings.Add("dloss", "dloss");
bulkCopy.DestinationTableName = "tbl_zloss";
bulkCopy.WriteToServer(dt);
}
Looks like you're using float which is an imprecise datatype.
Use decimal to get exact values. Precision and scale depend on your data

how to split date & time from xml

i have an XML file which contain date & time like this
<date>3/24/2014</date>
<time>9:00 AM</time>
</playdate>
i store this data in a data set & want to add in data table. i write this code for getting data
DataRow dr = dt.NewRow();
dr["StartDate"] = ds.Tables[0].Rows[i][1].ToString();
dr["StartTime"] = ds.Tables[0].Rows[i][1].ToString();
But the problem is when i export data in excel file i got both date & time in excel file in same column. i want date in my StartDate & time in StartTime . how can i split XML data
EDIT
string url = #"c:\temp\TestXML.xml";
StreamReader reader = new StreamReader(url);
string input = reader.ReadToEnd();
input = input.Trim();
input = input.Replace("- <", " <");
input = input.Replace(" & ", " & ");
input = input.Replace("W&W", "W&W");
input = input.Replace("", "
");
int userid = 0;
int j = 1;
try
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(input));
// Creating Data Table according to Table Value Parameter in Database
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("CalenderName", typeof(string)));
dt.Columns.Add(new DataColumn("EventName", typeof(string)));
dt.Columns.Add(new DataColumn("StartDate", typeof(DateTime)));
dt.Columns.Add(new DataColumn("EndDate", typeof(DateTime)));
dt.Columns.Add(new DataColumn("StartTime", typeof(DateTime)));
dt.Columns.Add(new DataColumn("EndTime", typeof(DateTime)));
dt.Columns.Add(new DataColumn("Venue", typeof(string)));
dt.Columns.Add(new DataColumn("Address", typeof(string)));
dt.Columns.Add(new DataColumn("City", typeof(string)));
dt.Columns.Add(new DataColumn("State", typeof(string)));
dt.Columns.Add(new DataColumn("ZipCode", typeof(string)));
dt.Columns.Add(new DataColumn("PhoneNo", typeof(string)));
dt.Columns.Add(new DataColumn("Link", typeof(string)));
dt.Columns.Add(new DataColumn("Email", typeof(string)));
dt.Columns.Add(new DataColumn("Performer", typeof(string)));
dt.Columns.Add(new DataColumn("Tags", typeof(string)));
dt.Columns.Add(new DataColumn("Price", typeof(string)));
dt.Columns.Add(new DataColumn("PriceURL", typeof(string)));
dt.Columns.Add(new DataColumn("EventDetails", typeof(string)));
dt.Columns.Add(new DataColumn("TimeZoneName", typeof(string)));
dt.Columns.Add(new DataColumn("TimeZoneOffsetAtCreation", typeof(int)));
dt.Columns.Add(new DataColumn("TabIndex", typeof(int)));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataRow dr = dt.NewRow();
string sDate = ds.Tables[2].Rows[i][0].ToString();
string sTime = ds.Tables[2].Rows[i][1].ToString();
DateTime dDateTime;
//cond: for checking the datetime parsing
if (DateTime.TryParseExact(sDate, "m/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dDateTime))
{
//sDate = dDateTime.ToString("M/dd/yyyy");
//dr["StartDate"] = sDate;
dr["StartDate"] = dDateTime;
}
//cond: for checking the datetime parsing
if (DateTime.TryParseExact(sTime, "hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dDateTime))
{
//sTime = dDateTime.ToString("h:mm:ss");
//dr["StartTime"] = sTime;
dr["StartTime"] = dDateTime;
}
dr["EventName"] = ds.Tables[0].Rows[i][1].ToString();
//dr["StartDate"] = ds.Tables[2].Rows[i][0].ToString();
//dr["EndDate"] = ds.Tables[2].Rows[i][0].ToString();
//dr["StartTime"] = ds.Tables[2].Rows[i][1].ToString();
//dr["EndTime"] = ds.Tables[2].Rows[i][1].ToString();
dr["Venue"] = ds.Tables[1].Rows[i][1].ToString();
dr["Address"] = ds.Tables[1].Rows[i][2].ToString();
dr["City"] = ds.Tables[1].Rows[i][4].ToString();
dr["State"] = ds.Tables[1].Rows[i][5].ToString();
dr["ZipCode"] = Convert.ToInt32(ds.Tables[1].Rows[i][6].ToString());
dr["PriceURL"] = ds.Tables[0].Rows[i][2].ToString();
dr["EventDetails"] = ds.Tables[0].Rows[i][4].ToString();
dt.Rows.Add(dr);
j++;
}
gvXmlData.DataSource = dt;
gvXmlData.DataBind();
btnExportData.Visible = true;
try with DateTime.ParseExact
string cellValue = "3/31/2014 9:00:00 AM";// this can be a cell value from excel file like ds.Tables[0].Rows[i][1].ToString()
DateTime date = DateTime.ParseExact(
cellValue,
"M/dd/yyyy h:mm:ss tt",
CultureInfo.InvariantCulture);
string startDate = date.ToString("M/dd/yyyy");
string startTime = date.ToString("h:mm:ss tt");
You are accessing same cell value in both StartDate and StartTime.
Most probably next cell should give you time value.
Also you can format date time same as specified in XML e.g. (mm/dd/YYYY)
Same goes with time hours minutes and seconds.
see code example here:
string sDate = ds.Tables[0].Rows[i][0].ToString();
string sTime = ds.Tables[0].Rows[i][1].ToString();
DateTime dDateTime;
DataRow dr = dt.NewRow();
//cond: for checking the datetime parsing
if (DateTime.TryParseExact(sDate, "M/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dDateTime))
{
//sDate = dDateTime.ToString("M/dd/yyyy");
//dr["StartDate"] = sDate;
dr["StartDate"] = dDateTime;
}
//cond: for checking the datetime parsing
if (DateTime.TryParseExact(sTime, "hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dDateTime))
{
//sTime = dDateTime.ToString("h:mm:ss");
//dr["StartTime"] = sTime;
dr["StartTime"] = dDateTime;
}

Sqlbulkcopy doesn't seem to work for me

I have created a datatable and trying to insert that datatable through SqlBulkCopy but somehow it doesn't seem to work for me....
I got the error,
The given value of type DateTime from the data source cannot be converted
to type decimal of the specified target column.
My Datasource is,
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("EmpId", typeof(Int64)));
dt.Columns.Add(new DataColumn("FromDate", typeof(DateTime)));
dt.Columns.Add(new DataColumn("ToDate", typeof(DateTime)));
dt.Columns.Add(new DataColumn("DaysPresent", typeof(decimal)));
dt.Columns.Add(new DataColumn("OpeningAdvance", typeof(double)));
dt.Columns.Add(new DataColumn("AdvanceDeducted", typeof(double)));
dt.Columns.Add(new DataColumn("RemainingAdvance", typeof(double)));
dt.Columns.Add(new DataColumn("SalaryGiven", typeof(double)));
dt.Columns.Add(new DataColumn("CreatedDate", typeof(DateTime)));
foreach (GridViewRow row in gridEmployee.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
DataRow dr = dt.NewRow();
dr["EmpId"] = Convert.ToInt64(((HiddenField)row.Cells[0].FindControl("HiddenId")).Value);
dr["FromDate"] = Convert.ToDateTime(GetMonthNumberFromAbbreviation(fromdate[1].ToString()) + '/' + fromdate[0].ToString() + '/' + fromdate[2].ToString());
dr["ToDate"] = Convert.ToDateTime(GetMonthNumberFromAbbreviation(todate[1].ToString()) + '/' + todate[0].ToString() + '/' + todate[2].ToString());
dr["DaysPresent"] = Convert.ToDecimal(((TextBox)row.Cells[3].FindControl("TxtDaysPresent")).Text);
dr["OpeningAdvance"] = Convert.ToDouble(((TextBox)row.Cells[4].FindControl("txtOpeningAdv")).Text);
dr["AdvanceDeducted"] = Convert.ToDouble(((TextBox)row.Cells[5].FindControl("TxtAdvanceDeducted")).Text);
dr["RemainingAdvance"] = Convert.ToDouble(((TextBox)row.Cells[6].FindControl("TxtClosingAdvance")).Text);
dr["SalaryGiven"] = Convert.ToDouble(((TextBox)row.Cells[7].FindControl("TxtSalary")).Text);
dr["CreatedDate"] = Convert.ToDateTime(System.DateTime.Now.ToString());
dt.Rows.Add(dr);
}
}
SqlBulkCopy sbc = new SqlBulkCopy(connectionString);
sbc.DestinationTableName = "SalaryDetails";
sbc.WriteToServer(dt);
sbc.Close();
And my destination Table looks like this,
alt text http://img231.imageshack.us/img231/5448/mytable.jpg
You need to specify a column mapping, as you don't have the same number of columns in the DataTable and the destination table.
You can do it like this:
sbc.ColumnMappings.Add("EmpId", "EmpId");
sbc.ColumnMappings.Add("FromDate", "FromDate");
// and so on, with the rest of the columns; and after that comes
sbc.WriteToServer(dt);
sbc.Close();

Categories

Resources