|
Hi
I've added a crystal report in my project & added tables of my sql server database in that report. In the display section of the crystal report, I also added the column of the tables those i want to display in my report. Now, I am querying the database and binding the dataset to report but my reports always shows no records. I've checked my code by debugging & there are always 4 recods in the table of the dataset but my reports shows nothing. My code is here:
string query = "SELECT AccountBalanceLog.[Date], Company.CompanyName, Accounts.AccountNo, AccountBalanceLog.BalanceIn, AccountBalanceLog.BalanceOut FROM AccountBalanceLog INNER JOIN Accounts ON AccountBalanceLog.AccountNo = Accounts.AccountNo INNER JOIN Company ON Accounts.CompanyID = Company.CompanyID INNER JOIN Employee ON Accounts.EmployeeID = Employee.EmployeeID WHERE Employee.EmployeeID='1' AND Company.CompanyID='2' AND Accounts.AccountNo='Oanda1'";
SqlConnection Conn = new SqlConnection(MyConnectionString.ConnectionString);
SqlCommand myCommand = new SqlCommand(query, Conn);
Conn.Open();
SqlDataAdapter adp = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adp.Fill(ds);
ReportDocument doc = new ReportDocument();
string cwd = System.IO.Directory.GetCurrentDirectory();
if (cwd.EndsWith("\\bin\\Debug"))
{
cwd = cwd.Replace("\\bin\\Debug", "");
}
doc.FileName = cwd + "\\CrystalReport2.rpt";
doc.SetDataSource(ds);
crystalReportViewer1.ReportSource = doc;
Conn.Close();
please guide me where is am missing something.
thanks in advance...
Regards...
Mudasser Hassan
|
|
|
|
|
I'm using this code(see below)to import data from an excel spreadsheet into my database.now the problem is that it throws "Object reference not set to an instance of an object"exception whenever it gets to this line
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
what am i missing or what am i doing wrong? plz help
public void ImportToStudent()
{
try
{
//Gets the filename, not the path
string filename = ofd.SafeFileName;
string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\..\\PSAtechZTimetableSystem\\SpreadSheet.xls" + "; Extended Properties='Excel 8.0; IMEX=1; HDR=YES'";
// Here is the call to Open a Workbook in Excel
// It uses most of the default values (except for the read-only which we set to true)
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
using (SqlConnection conPSAtechZ = new SqlConnection(connection))
{
conPSAtechZ.ConnectionString = connection;
using (SqlCommand commandExcel = conPSAtechZ.CreateCommand())
{
System.Data.DataTable table = new System.Data.DataTable();
commandExcel.CommandText = "SELECT [StudentID] AS [StudentID]," + "[ModuleCode] AS [ModuleCode], " + "FROM [Sheet1$]";
//Open the Excel Connection
conPSAtechZ.Open();
using (SqlDataReader dr = commandExcel.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read() && dr.HasRows)
{
lblResults.Text = "Importing...";
try
{
studentdal.RegisterStudents(new RegisterStudent(Convert.ToString(dr["StudentID"]), Convert.ToString(dr["ModuleCode"])));
commandExcel.CommandType = CommandType.StoredProcedure;
lblResults.Text = "Successfully Imported!!";
}
catch (Exception Ex)
{
MessageBox.Show("Error!!\n " + Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
dr.Close();
}
}
}
}
catch (Exception EX)
{
MessageBox.Show("The spreadsheet is not in the correct format!\n\n" + EX.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
|
|
|
|
|
Twyce wrote: I'm using this code(see below)to import data from an excel spreadsheet into my database.now the problem is that it throws "Object reference not set to an instance of an object"exception whenever it gets to this line
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t",
false, false, 0, true, true, true);
what am i missing or what am i doing wrong? plz help
It means that one of the objects you're trying to access is null . Start your application in the debugger, step into this line (it'll automatically when throwing the exception) and see which of them is null.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
It's likely the variable ofd is null when you reach the error line.
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
You posted "twyce"
|
|
|
|
|
I'm using this code(see below)to import data from an excel spreadsheet into my database.now the problem is that it throws "Object reference not set to an instance of an object"exception whenever it gets to this line
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
what am i missing or what am i doing wrong? plz help
public void ImportToStudent()
{
try
{
//Gets the filename, not the path
string filename = ofd.SafeFileName;
string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\..\\PSAtechZTimetableSystem\\SpreadSheet.xls" + "; Extended Properties='Excel 8.0; IMEX=1; HDR=YES'";
// Here is the call to Open a Workbook in Excel
// It uses most of the default values (except for the read-only which we set to true)
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
using (SqlConnection conPSAtechZ = new SqlConnection(connection))
{
conPSAtechZ.ConnectionString = connection;
using (SqlCommand commandExcel = conPSAtechZ.CreateCommand())
{
System.Data.DataTable table = new System.Data.DataTable();
commandExcel.CommandText = "SELECT [StudentID] AS [StudentID]," + "[ModuleCode] AS [ModuleCode], " + "FROM [Sheet1$]";
//Open the Excel Connection
conPSAtechZ.Open();
using (SqlDataReader dr = commandExcel.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read() && dr.HasRows)
{
lblResults.Text = "Importing...";
try
{
studentdal.RegisterStudents(new RegisterStudent(Convert.ToString(dr["StudentID"]), Convert.ToString(dr["ModuleCode"])));
commandExcel.CommandType = CommandType.StoredProcedure;
lblResults.Text = "Successfully Imported!!";
}
catch (Exception Ex)
{
MessageBox.Show("Error!!\n " + Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
dr.Close();
}
}
}
}
catch (Exception EX)
{
MessageBox.Show("The spreadsheet is not in the correct format!\n\n" + EX.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
|
|
|
|
|
Please edit your post and use <pre></pre> tags
|
|
|
|
|
Hi
any ideas of how to do this?
I have data in a MDB, and i want to import the data to a SQL Database
I need to upload it in a ASP.Net page coded in C#, copy to the SQL Server and then, delete the file.
Any ideas?
I tried some code and make it work, but gives me an error when i try to delete the file (it says that the file is being used for other process). So i want to know if there is another way to do this.
thanks
|
|
|
|
|
Did you close all the connections before trying to delete the database file?
|
|
|
|
|
Yes, i closed all the connections before deleting the database.
|
|
|
|
|
Greetings Comrades,
Does anybody knows how to clear Stream?
Stream memoryStream = new MemoryStream();
...
memoryStream.Flush() - does nothing
memoryStream.SetLength(0) - calls AccessViolationException ("memory is corrupt")
Any help will be just fine. Thanks!!!
One nation - underground
|
|
|
|
|
you close and dispose it.
|
|
|
|
|
Did you use this :
memoryStream.Dispose();
|
|
|
|
|
But in this case am I able to continue using MemoryStream ?
One nation - underground
|
|
|
|
|
Nope. The only way to clear it out is to Seek to position 0 and write 0's to every known position. Depending on the size of the Stream, it's porobably going to be faster, or at least easier, to just kill the existing stream and create a new one.
|
|
|
|
|
Thank you.
One nation - underground
|
|
|
|
|
Try this out
MemoryStream ms = new MemoryStream();
.......
......
ms.SetLength(0);
ms.Position = 0;
Hope this Works!!!
|
|
|
|
|
Hi yall,
I've written an app which plays wav files continually using DirectSound.
Everything works fine until the app form loses focus, which causes the sound to stop playing.
Thing is, i'd like the app to keep playing the sounds in the background while doing other stuff.
How can I do this???
Thanx for any help,
Dominic
|
|
|
|
|
Found this in the CP archives:
DirectSound plays only when the window which is passed to SetCooperativeLevel,
is foreground. If it passes to background, the playback stops until again the wnd becomes foreground. Unfortunately, this is the way how DirectSoundBuffer works.
PlaySound API is process-wise (application-wise). Two (or more) processes can play sounds simultaneously but a single application can play one sound in a given time period. How intensively your app is going to play/stop sounds? (If it's not so intensive, maybe creating a child process per sound would do).
...
Blog link to be reinstated at a later date.
|
|
|
|
|
Set BufferDescription's GlobalFocus property to true
|
|
|
|
|
Hi,
I have a kind've strange problem in VS 2005. I have an application which, if i run and i put a breakpoint in front of creating a connection, works just fine. But if I simply run it, throws this error
{"The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception."}
Here is the code that's causing it:
_sqlConnection = new SqlConnection(Settings.ConnectionString);
where _sqlConnection is declared like
private static SqlConnection _sqlConnection = null;
and Settings.ConnectionString like
private static string _connectionString = string.Empty;
public static string ConnectionString
{
get
{
Configuration config = ConfigurationManager.OpenExeConfiguration(Settings.AppName);
_connectionString = EncryptDecrypt.Decrypt(config.ConnectionStrings.ConnectionStrings["ConnectionString"].ToString(),Settings.EncPassword);
return _connectionString;
}
}
Any suggestions?
Thank you
|
|
|
|
|
First post so be gentle :-p
I'm currenlty working on my first semi-serious program for my local RPG gaming group. Got the design sorted no problem, but one thing seems to be eluding me and i cant seem to find the right answer on the net anywhere(probably not asking right questions, but hey ho)
Anyway my problem is this:
I have a series of forms. On each on this forms are various controls such as text boxes, radio control groups, drop down boxes etc. These contain information on character information(such as stats, skills etc)
I'm trying to find the way i can save and then at a later date load this information back from either all the forms or simply one of the forms, so that they dont have to pick the settings or re-enter the information each time they start the program.
Any help would be appreciated, but please i must warn you am still new to c# so nothing too complex please
Thanks in Advance
|
|
|
|
|
Write a class that represents this form as a model, copy the values from the controls to the model, and then save the data to the disk.
|
|
|
|
|
A settings file would be the easiest way.
You can find it under the Properties tab in the solution explorer.
Add variables to it, and then you can save and load data using
<br />
*** = Properties.Settings.Default.***;<br />
<br />
Properties.Settings.Default.*** = ***<br />
Properties.Setting.Default.Save();<br />
This way your variables will be saved between sessions.
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
would this work with diffrent users(EG Main, Person1, Person2) all haveing seperate files ? (named of course)
|
|
|
|
|