|
Assuming the stored procedure is returning a result set to a DataSet, then just bind to the table returned within the DataSet. Use of a stored procedure versus a SQL Statement to retunr data has no effect on data binding.
Ron
|
|
|
|
|
Hello,
I want to show Datagrid values in CrystalReportViewer by using C# can anybody send me sample code to do that? Please....
Regards,
AbuBakar
|
|
|
|
|
are u using WindowsApplication or WebApplication?
|
|
|
|
|
I am using Window Application not Web Application....
|
|
|
|
|
Hi all!!
I have a problem with the SQLDataReader. I don't understand it 100%. Please take a look at my code below for returning the titles to a combobox, it works fine just as it is:
public static IDataReader GetTitles()
{
SqlDataReader objDr = null;
// Create instance of connection and command object
SqlConnection objConn = new
SqlConnection(PLATTERGlobals.ConnectionString);
SqlCommand objCmd = new SqlCommand("sp_Title_GetAllTitles", objConn);
// Mark the command as a SPROC
objCmd.CommandType = CommandType.StoredProcedure;
// Add parameters to SPROC
SqlParameter[] objParamArray = new SqlParameter[] {};
// Execute the statement
try
{
objConn.Open();
objDr = objCmd.ExecuteReader();
}
catch (SqlException ex)
{
HandleError(objParamArray, ex, "sp_Title_GetAllTitles");
}
finally
{
if (objConn.State == ConnectionState.Open)
{
//objConn.Close();
}
//objConn.Dispose();
//objCmd.Dispose();
}
// Return the titles
return (objDr);
}
But I can't understand why I had to remove (//) my code in the finally block? I always like to close my connections and to dispose of them as soon as possible. But when I do it here, then it brings back a FieldCount error. Why is this? And when is the connection closed and destroyed? Do I still have to close explicitly?
Please can someone advise.
Regards
|
|
|
|
|
The connection has to be open as long as you use the data reader.
You can specify CommandBehavior.CloseConnection when you create the reader to make the reader close the connection when the reader is closed, otherwise you have to close it explicitly.
Personaly I prefer to explicitly close the connection.
---
b { font-weight: normal; }
|
|
|
|
|
Hey!!
All that I want to do is populate a combo box with titles, like Mr, Mrs, Miss, etc. Is this the best way to go about it? I don't like to have an open connection all the time.
|
|
|
|
|
You only have to keep the connection open as long as you read from the data reader.
Open the connection, get the reader, read from it and put the data in the control, close the reader and close the connection.
---
b { font-weight: normal; }
|
|
|
|
|
I understand what you are trying to say, but my confusion comes in because I am returning the SQLDataReader to the combo box.
In my register.aspx.cs file I call the Member class's static GetTitles method like this:
cboTitles.DataSource = Member.GetTitles();
cboTitles.DataValueField = "TitleID_PK";
cboTitles.DataTextField = "TitleName";
cboTitles.DataBind();
The static GetTitles method looks like this in the Member class:
public static IDataReader GetTitles()
{
return MemberDA.GetTitles();
}
And the return method I have posted already. So I'm still confused as to where I must close the SQLDataReader.
Regards
|
|
|
|
|
You have to close the data reader after you have read all the data you need from it. In your code you would have to do that after the call to DataBind.
When you are moving data through several layers, you should consider to read the data into a DataSet, or a list of objects.
If you create a title class that has the properties you need in the combo box, you can use an ArrayList of such objects as a data source:
Class Title {
private int id;
private string name;
public Title(int id, string name) {
this.id = id;
this.name = name;
}
public int TitleID_PK { get { return this.id; } }
public string TitleName { get { return this.name; } }
}
You create the ArrayList by reading through the data reader:
ArrayList list = new ArrayList();
while (reader.Read()) {
list.Add(new Title(reader.GetInt32("TitleID_PK"), reader.GetString("TitleName")));
}
reader.Close();
---
b { font-weight: normal; }
|
|
|
|
|
How to create new column to display at datagrid??
DataSet ds = new DataSet();
DataTable t = new DataTable();
ds.Tables.Add(t);
DataColumn cNo = new DataColumn("No", Type.GetType ("System.Int32"),"");
cNo.AutoIncrement = true;
cNo.AutoIncrementSeed = 1;
cNo.AutoIncrementStep = 1;
t.Columns.Add(cNo);
those is wat i hav write, but stil can display the new column??
angela
|
|
|
|
|
after u add new column try to refresh ur table or close ur SqlConnection and open again
|
|
|
|
|
just wonder isn't my coding is put before
myConnection.Open();
da.Fill(ds);
myConnection.Close();
or after tat statement??
wat d coding for refresh function??
angela
|
|
|
|
|
i think u r adding datatable in dataset before adding column to datatable.
so try to add data table after adding datacolumn to datatable.
rahul
|
|
|
|
|
DataSet ds = new DataSet();
DataTable t = new DataTable();
ds.Tables.Add(t);
DataColumn cNo = new DataColumn("No", Type.GetType ("System.Int32"),"");
cNo.AutoIncrement = true;
cNo.AutoIncrementSeed = 1;
cNo.AutoIncrementStep = 1;
t.Columns.Add(cNo);
//1. close ur sqlconnection
//2. load ur data from ur table (select commad example: select * from urtable(when u give select * command then u can view ur new column...))
//3. open ur connection string
|
|
|
|
|
then d i need to add a column in my datagrid for this new autoincrement column. how i bind all of this to my datagrid?
angela
|
|
|
|
|
Hello!
I am making windows application. Design of that application need to be a little caracteristic. I don't wont to allow my users to change XP theme for my application.I have some stylesheat.dll for different themes. I don't know how to include that .dll files into my project because that is not type of .com files. Project is using default theme that is chosen into Display Properties -Appearence - Color scheme (Default Blue, silver, olive green).
I am working with C#. Plese, if you now how can I do that... write to me...
I am not shure is that even posible.
My e-mail is: snjezana@mpa.co.yu
Thank you,
Snowwhite
Snowwhite
|
|
|
|
|
How can the user change the XP theme of ur application,
The theme depends on the Operating System
if i have created an application on XP the application will have XP look only when it is run on that machine
but if i run the same application on 2000 the application will have 2000 theme and the color or the looks will be of 2000.
This is want i know.
if there is any way in which the applications Theme can be set constant for all the O.S.
Please write back.
Regards,
Pramod
|
|
|
|
|
I have made a program to play video file in directx (directx.AudioVideoplayback)! It worked well ! But I couldn't find the way to handle the video.owner !
when I did set the video.Owner = (name of my panel); I wanted to set video to full screen mode by double click on the video (in bool property video.FullScreen).
I tried to add Double Click EventHandler to my panel or video.Owner but It didn't work !
How can I do this ? Any ideas ... ?
-- modified at 0:24 Monday 6th March, 2006
|
|
|
|
|
????????????????????????????????????????????????????????????????????
-- modified at 9:29 Monday 6th March, 2006
|
|
|
|
|
I want to upload an image in my asp page but before uploading a want to check if the size of that image is: height = 80 and widht = 100.
Please look into this.
Deepak Anish
Computer Programmer
Maxumise Fiji Ltd
Suva, Fiji
|
|
|
|
|
deepak1 wrote: but before uploading
I don't think that you coudl do that in Javascript... meaning: I don't think you could do that at all.
On the other hand, once recieved on the server side you could check the pic before saving it into the database (and write a little confirmation / error message).
To test on the server side:
Bitmap bmp = new Bitmap(new MemoryStream(buffer));
if(bmp.Width > 100 || bmp.Height > 100)
....
|
|
|
|
|
After much thinking you could submit the data not through an FileUploadInput but through an ActiveX / JavaApplet, in which case you could do all the test you like....
|
|
|
|
|
Hello,
I am trying to execute the following code from a background worker's DoWork Event Handler and getting the error :Cross Thread Operation etc..etc... Can you kindly show me some ways to do this work. The following code does Extract Text from a MS word document file.
string textData ;
try
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.ApplicationClass();
object nullobj = System.Reflection.Missing.Value;
object file = fileName;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
textData = (data.GetData(DataFormats.Text)).ToString().Trim();
doc.Close(ref nullobj, ref nullobj, ref nullobj);
app.Quit(ref nullobj, ref nullobj, ref nullobj);
}
catch (Exception error)
{
MessageBox.Show("Error Extracting Resume Text : " + error.Message);
}
-- modified at 16:24 Sunday 5th March, 2006
|
|
|
|
|
My guess is that the code that you're running happens to raise an exception and hit the line that displays a MessageBox. That operation is not allowed on a background thread so that's probably where it yells at you.
Try commenting out the "MessageBox.Show.." line and see if you still get that error.
Have you verified that yet?!
----
www.muzikstor.com
|
|
|
|