|
you can achieve this scenario in the database itself...
Code:
create table test_tab (m1 numeric, m2 numeric, m3 numeric)
insert into test_tab values (1,2,3)
insert into test_tab values (4,6,8)
insert into test_tab values (5,7,9)
select m1,m2,m3 , (m1+m2+m3) as tot from test_tab
<pre>
<div class="ForumSig">Padmanabhan
My Articles:
<a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=5686247">Articles</a>[<a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=5686247" target="_blank" title="New Window">^</a>]
My latest Article:
<a href="http://www.codeproject.com/KB/office/Word_Automation_Part1.aspx">Word Automation</a>[<a href="http://www.codeproject.com/KB/office/Word_Automation_Part1.aspx" target="_blank" title="New Window">^</a>]</div>
|
|
|
|
|
How to bind two data tables which are in the same dataset to a datagrid????Below is tha code i've written so far
OleDbDataAdapter da_pay = new OleDbDataAdapter();
DataSet ds_pay = new DataSet();
OleDbCommand pay_cmd = new OleDbCommand("select Group from group_details where [Group]='"+descriptiondpdwnlist .SelectedItem .Value +"'",con2);
da_pay.SelectCommand = pay_cmd;
da_pay.Fill(ds_pay,"bill_group");
DataTable pay_dt=ds_pay .Tables ["bill_group"];
OleDbCommand pay_cmd1 = new OleDbCommand("select Description from description_details where [Description]='"+descrptndpdnlt .SelectedItem .Text +"'",con2);
da_pay.SelectCommand = pay_cmd1;
da_pay.Fill(ds_pay ,"Bill_description");
DataTable pay_dt1=ds_pay .Tables ["Bill_description"];
con2.Close();
|
|
|
|
|
public void GridBind()
{
DataTable dtfirst;//your first datatable
DataTable dtsecond;//your second datatable
DataTable dtOverall = new DataTable();
dtOverall.Columns.Add("id");//name of the first table column
dtOverall.Columns.Add("name");//name of the first table column
dtOverall.Columns.Add("email");//name of the second table column
dtOverall.Columns.Add("phone");//name of the second table column
//..
//..
//..
int first = dtfirst.Rows.Count;
int second = dtsecond.Rows.Count;
int overAllTableCount = (first > second) ? first : second;
for (int i = 0; i < overAllTableCount; i++)
{
int id = 0;//according to the column name and datatype use here
string name = string.Empty;
string email = string.Empty;
string phone = 0;
//...
//..
//..
if (i < first)
{
id = int.Parse(dtfirst.Rows[i]["id"].ToString());
name = dtfirst.Rows[i]["name"].ToString();
}
if (i < second)
{
email = second.Rows[i]["email"].ToString();
phone = int.Parse(second.Rows[i]["phone"].ToString());
}
DataRow drOverall = dtOverall.NewRow();
drOverall["id"] = id;
drOverall["name"] = name;
drOverall["email"] = email;
drOverall["phone"] = phone;
dtOverall.Rows.Add(drOverall);
}
}
//hope you understood
|
|
|
|
|
Hello,
In my application i am having two forms.
In the first form i am having a textbox and in the
second form i am having a datagridview and a button back.
when the button back is clicked i like to get the data from the
datagridview to the textbox in the first form.
Please help me how i can do this.
I have no sound about this....plz help me
Thanks in advance
|
|
|
|
|
Just showing example :
public class Form1 : Form
{
...
public string MyText
{
set { this.textBox1.Text = value; }
}
...
}
public class Form2 : Form
{
private Form1 form1;
public Form2(Form1 form1)
{
this.form1 = form1;
}
private void buttonBack_Click(object sender, EventArgs e)
{
this.form1.MyText = "Data from DataGridView here...";
}
}
|
|
|
|
|
This is NOT a good way to do it as now Form2 is coupled to Form1. Also, what if there are hundreds of objects that need the data? Are you going to have hundreds of constructor overloads?
The correct way to do this is to raise an event in Form2 that Form1 (and any other interested parties) subscribes to. If any data needs to be passed, then a custom class derived from event args should be used with that data being passed as a property. This is the way all the classes provided by Microsoft do it, with good reason.
A quick example:
using System;
using System.Windows.Forms;
public class Form1 : Form
{
public Form1() { }
public void ShowNewForm2()
{
Form2 form2 = new Form2();
form2.CustomEvent += new EventHandler<CustomEventArgs>(form2_CustomEvent);
form2.Show();
}
void form2_CustomEvent(object sender, CustomEventArgs e)
{
}
}
public class Form2 : Form
{
public event EventHandler<CustomEventArgs> CustomEvent;
public Form2() { }
protected virtual void OnCustomEvent(CustomEventArgs e)
{
EventHandler<CustomEventArgs> eh = CustomEvent;
if (eh != null)
eh(this, e);
}
public void PerformCustomEvent()
{
OnCustomEvent(new CustomEventArgs(123));
}
}
public class CustomEventArgs : EventArgs
{
public CustomEventArgs(int yourData)
{
YourData = yourData;
}
public int YourData
{
get;
private set;
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
thank you for giving me an idea.
i got it
|
|
|
|
|
See my reply to stancrm - there is an example there that gives you the idea.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thank you for giving me a nice example.
|
|
|
|
|
i have datatable which is returned from storedprocedure,now i want to pass that data table's values to crystal report to view,
i have tried through parameters but can't get desired result.the database fields i cant assign to report because the values come from different sources in storedprocdure
Regards
|
|
|
|
|
You need to create a strongly typed DataSet in your project, one that represents the data schema from the stored procedure.
Then you need to base your report off the strongly typed DataSet.
Then just assign the DataSource property of the CrystalReport to the instance of the DataSet returned from your your stored procedure.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
i am on a windows project and i applied backgroundimage to all the forms earlier. And now when i want to apply another new background image to a form then , i can see the new image as background image to a form in visual studio but at the runtime no image is displayed, and the form is displayed with background color but not with the image. After that through code also i tried using imagelist . Then indexoutofrange exception is coming.
Please suggest me the required answer. Urgent.
|
|
|
|
|
I have a database driven menu (dynamic menu). Can someone help me with code to display the appropritate page based upon menu item selected
|
|
|
|
|
Hi,
how can i open an existing excel file as a new document.
and if user close it from upper left close(X) button of doc,
then it should ask to save the document as a new excel doc file.
|
|
|
|
|
hi everybody
i made a program which works in system tray when i minimize it
everything is ok till here
but when i made its exe it gives error and doesnt open the exe windows form
it is error because of the icon that i have choosen for the notifyicon
it cant find the source file when i run the exe
i tried to add an icon file to the program to manage it
but it gives the same error
it works when i dont choose any icon for notifyicon
so how i can manage to choose an icon for notifyicon
i will be happy if u help me
|
|
|
|
|
Assuming the file you are using is a valid icon resource, add the file to the project's resources
Project | YourProjectProperties then the Resources tab on the left.
Set the Icon for the NotifyIcon in code
notifyIcon.Icon = Properties.Resources.youricon
The only time I've had an issue with this was trying to use 'vista' icons. IIRC, the 256x256 caused problems, but that's not needed for a tray icon anyway!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
thanks for the reply
i think i did it because i dont get an error when i run it
but now i have a new problem
when i try to make its .exe i got an error which says
form1.cs <23,32> : the name 'Properties' doesnt exist in the current context
i use Visual Studio's own Comand prompt to make it .exe
i think i should add one more file to debug
but which one i dont know
|
|
|
|
|
hey
i try to manage my problem with the codes below there
Icon theicon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("PanelDenemem.favicon.ico"));
but i get an error also here like
Value of 'null' is not valid for 'stream'
but i have the icon there
so what can be the problem here ??
|
|
|
|
|
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string connection1 = ConfigurationManager.AppSettings["conn"];
OleDbConnection con1 = new OleDbConnection(connection1);
con1.Open();
OleDbDataReader dr;
string query = "select DISTINCT DEPARTMENT from TIME_DETAILS ";
OleDbDataAdapter da1 = new OleDbDataAdapter(query,con1);
DataSet ds1 = new DataSet();
//da1.Fill(ds1);
OleDbCommand cmd = new OleDbCommand(query,con1);
da1.SelectCommand=cmd;
da1.Fill(ds1,"dept");
DataTable dep=ds1.Tables["dept"];
dr = cmd.ExecuteReader();
DropDownList2.DataSource=dep;
if(dep.Rows.Count>0)
{
foreach (DataRow row in dep.Rows )
{DropDownList2.Items.Add(row[0].ToString());}
}
//while (dr.Read())
//{
//DropDownList2.Items.Add(dr[0].ToString());
//DropDownList2.DataValueField.Insert(dr[0]);
// DropDownList2.Items.Add(New ListItem(dr[0].ToString())));
// }
}
|
|
|
|
|
0. Use the <pre></pre> to make your code pretty, see:
ankitjain1110 wrote:
foreach (DataRow row in dep.Rows )
{DropDownList2.Items.Add(row[0].ToString());}
1. Why are you re-populating on the SelectedIndexChanged event? Populate the picklist ONCE when you load the control.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
While you are adding items inside foreach loop then you don't need to set datasource to dropdownlist.
string connection1 = ConfigurationManager.AppSettings["conn"];<br />
OleDbConnection con1 = new OleDbConnection(connection1);<br />
con1.Open();<br />
<br />
<br />
OleDbDataReader dr;<br />
<br />
string query = "select DISTINCT DEPARTMENT from TIME_DETAILS ";<br />
OleDbDataAdapter da1 = new OleDbDataAdapter(query,con1);<br />
DataSet ds1 = new DataSet();<br />
OleDbCommand cmd = new OleDbCommand(query,con1);<br />
da1.SelectCommand=cmd;<br />
da1.Fill(ds1,"dept");<br />
DataTable dep=ds1.Tables["dept"];<br />
dr = cmd.ExecuteReader();<br />
<br />
if(dep.Rows.Count>0)<br />
{<br />
foreach (DataRow row in dep.Rows )<br />
{<br />
DropDownList2.Items.Add(new ListItem(row[0].ToString(),row[0].ToString()));<br />
}<br />
<br />
}
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
try this:
DropDownList2.DataSource = ds1.Tables["dept"];
DropDownList2.DataTextField = "DEPARTMENT";//the col which you want to display
DropDownList2.DataValueField = "";//DEPARTMENT id or anything else
DropDownList2.DataBind();
|
|
|
|
|
I have windows app and am using c#. I want to launch default browser from c# program and pass some parameters. Basically what i have is content type (eg. "application/msword") and byte array of content (word/excel/pdf docs in byte array). I want to pass these two parameters to browser and let it open the doc. Can anybody please guide me to achieve this? One more thing i don't want to create any file in local disk.
Thanks.
|
|
|
|
|
Are you saying the document is not on your disk or some remote machine, but in memory? If yes, simply save it to a temporary location and display it from there. That is what even browsers do.
Once you've saved it, try Process.Start("URL of your document") . That will open the default handler (generally, MS Word) though. Launching a local .DOC file with your default browser might be slightly more complicated, and I'm not even sure why you'd want to do that.
Cheers,
Vikram. (Proud to have finally cracked a CCC!)
|
|
|
|
|
Thanks Vikram, here are my problems:
1. I actually don't want to store doc in local machine and handle creation and deletion of files. If in any case end user have very minimum rights i may not be able to create file even. Here maybe i should think of memory stream?
2. "Launching a local .DOC file with your default browser might be slightly more complicated, and I'm not even sure why you'd want to do that. " i din't get this? Are you suggesting to launch directly ms word, excel or acrobat softwares and display docs in them instead of using browser? if yes, the problem with this approach is i need to know and code for all types of docs, if i use browser i no need to bother about this as far as i supply content type and byte array.
Thanks.
|
|
|
|