Hi,
In a form Form13.cs I have defined a function load which retrieves some info from the database as below
public
void load(){
string ret = string.Format("select partyid, firstname, lastname, middleinit as minit, city, state, mobilephone, emailid, address, zipcode, ssn, homephone, workphone, employer from responsibleparty"); DataTable dt1 = new DataTable();dt1 = obj.gettable(ret);
dataGridView1.DataSource = dt1;
obj.closecon();
for
(int i = 0; i < (dataGridView1.Rows.Count-1); i++){
dataGridView1.Rows[i].Cells[0].Value =
"Delete";dataGridView1.Rows[i].Cells[1].Value =
"Update";}
}
now I want to use this function in another form Forn42.cs. How to call this function in Form42.cs
thanks
Kirtan PatelPosted May 29, 2009, 3:22 PM
da.Fill(ds, "patientinfo", "scheduleappointment"); // here I am getting error.
change this line to
da.Fill(ds, "anynamehere");
sachi vasishtaPosted May 28, 2009, 3:52 AM
Hi,
In a form form7 I want to use a function called loadtableschedule() which I have declared in class3.cs. This function, loadtableschedule has to get some string value from form7 and it does the fetching of data from two db tables.
namespace
Medical_Office2009{
class Class3 // refreshing of forms{
public static DataSet loadtableschedule(string recdate) // schedule refreshing{
OdbcConnection con = new OdbcConnection("Dsn=Medoffice");con.Open();
string stm = string.Format("select firstname as FirstName,lastname as LastName,address as Address,city as City,statecode as State,phonemobile as Mobile_Phone,phonehome as Home_Phone,sex as Sex,scheduledate as Date,provider as Doctor,starttime as StartTime,endtime as EndTime,reason as Reason,priority as Priority,scheduledthru as Mode from patientinfo,scheduleappointment where scheduledate='{0}' and scheduleappointment.patientid=patientinfo.patientid order by starttime", recdate); OdbcCommand ocom = new OdbcCommand(stm);ocom.Connection = con;
OdbcDataAdapter da = new OdbcDataAdapter(ocom); DataSet ds = new DataSet();da.Fill(ds,
"patientinfo", "scheduleappointment"); // here I am getting error.}
}
}
and in form7 I will call this function like below
if
(assformname == "form2obj"){
DataSet ds = Class3.loadtableschedule(fulldate);fobj2.dataGridView1.DataSource = ds.Tables[0];
Form7.ActiveForm.Close();}
else if (assformname == "form3obj"){
DataSet ds = Class3.loadtableschedule(fulldate);fobj3.dataGridView1.DataSource = ds.Tables[0];
Form7.ActiveForm.Close();}
Here in loadtableschedule() function I will make use of two db tables. I have used other functions (posted by kitan patel) which perform the same thing as loadtableschedule(), but with one db table.
thanks
sachi vasishtaPosted May 22, 2009, 4:04 AM
Kirtan I fixed that error. For that I just have to change the dgv's modifier property to public and I have to use that form's(Form13 in my case) object in my another form(Form20)
thanks
sachi vasishtaPosted May 22, 2009, 3:16 AM
thanks kirtan for your kind reply. Kirtan but the application is giving error. I have created a class Class1.cs and copyied the code you have sent and while I wrote the the code in Form20.cs as below
DataSet ds=Class1.loadData();
dataGridView1.DataSource=ds.Tables[0];
it gave me the following error
The name dataGridview1 doesnot exist in the current context.
help!
thanks
Kirtan PatelPosted May 20, 2009, 5:00 PM
namespace WindowsApplication2
{
class Class1
{
public static DataSet loaddata()
{
SqlConnection con = new SqlConnection("Your Connection String ");
con.Open();
SqlCommand comm = new SqlCommand("select partyid, firstname, lastname, middleinit as minit, city, state, mobilephone, emailid, address, zipcode, ssn, homephone, workphone, employer from responsibleparty",con)
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds,"VTable");
con.Close();
return ds;
}
}
}
then in Form20 Call Method Like Below
Form20_Load() ..... blah blah...
{
DataSet ds = Class1.loadData();
dataGridView1.DataSource = ds.Tables[0];
}
sachi vasishtaPosted May 20, 2009, 6:35 AM
Kirtan PatelPosted May 20, 2009, 4:07 AM
?
or anything else ?