Hello all,

It has been long since i am facing this problem. I want to convert my datagridview data to pdf format.
I have searched a lot but couldnt find any. Need your help.

Regards,
Ajinkya

Hey people,

I have a question. I may sound like a person with no knowledge. Isn't there any other control than datagrid or datagridview, to display data from table. Please help me to know more about this.

Regards

ajinkya

Hey guys,
Here's the thing. I have a database in MS access. I have made an application that has to access this DB. Now this database
is on another machine. Lets call it pc1. pc1 and my machine are in same wireless network. But when i try to connect to the database connection fails. Do need to put on internet or is there a workaround for this? let me put connection string i am using for this. Please let me know if there's anything wrong with it.

[CODE]Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\xxx.xxx.xxx.xxx\C:\Users\user1\Documents\DB1.accdb;[/CODE]

Thanks
Ajinkya

Hello people,

I have an application that updates a table. In this application i have a combobox where i load id of record
on form load. Let me paste my code to be more clear about my problem.

[CODE]
Private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

string q = "Select AREA, [PAYING AUTHORITY],[PURCHASE ORDER No], [BILL No], [BILL DATED], [MATERIAL VALUE], [BILL VALUE], [AMOUNT PASSED] , [SUPPLY PARTICULAR], [PAYMENT DETAILS], [C-FORM No], T_ID from transact1 where t_id = '" +comboBox1.SelectedItem+ "' ";

            SqlCommand cmmd = new SqlCommand(q, on6);

            SqlDataReader drr = cmmd.ExecuteReader();

            while (drr.Read())
            {
                //MessageBox.Show("Record With this Transaction Exist. Please Press OK to Continue.....");

                txtarea.Text = drr["AREA"].ToString();
                textBox2.Text = drr["PAYING AUTHORITY"].ToString();
                richdescp.Text = drr["PURCHASE ORDER No"].ToString();
                txtbill.Text = drr["BILL No"].ToString();
                dateTimePicker1.Text = drr["BILL DATED"].ToString();
                txtamt.Text = drr["MATERIAL VALUE"].ToString();
                txtamtpas.Text = drr["BILL VALUE"].ToString();
                textBox1.Text = drr["AMOUNT PASSED"].ToString();
                richrem.Text = drr["SUPPLY PARTICULAR"].ToString();
                txtchq.Text = drr["PAYMENT DETAILS"].ToString();
                textBox3.Text = drr["C-FORM No"].ToString();

            }
            drr.Close();

                on6.Close();

        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        }

}[/CODE]

Everytime i try to load data in the form. It gives me error that "String was not recognized as valid date time".
I tried lot of things but it didn't help. Can anybody please help me with this problem?

Thanks and Regards
Ajinkya

@Momerath,

Yes. I am using connection entire time.
I am trying to connect to sql server 2005.
Here's the code i am using to connect to the database.

[CODE] try
{

            string strr = "Server=server name;Data Source=xxx.xxx.x.x;Network Library=DBMSSOCN;Initial Catalog=MIS;Connect Timeout=10000;User ID=sa;Password=";
            SqlConnection con1 = new SqlConnection(strr);
            con1.Open();

            if (con1.State.Equals(ConnectionState.Open))
            {
                MessageBox.Show("Connection Established");
            }
            con1.Close();
        }

        catch (Exception)
        {
            MessageBox.Show("Could not establish connection to server");
        }[/CODE]

Hey guys,

I have an application that connects to DB that is on a remote PC.
Problem is after a couple of minutes or so, it starts throwing exception.

  1. The specified network name is no longer available.
  2. Connection was forcibly closed by remote host.
  3. connection was closed by software on the remote machine.

I couldn't find any solution for these problems.
Please help me with this one.

Thanks and regards
ajinkya

Hey Ddanbe,
I am extremely thankful for your reply. It really helped me with most of my problem, except for one. This code prints all text in portrait format. I want it to be printed in landscape format. I tried making some adjustments in the code but it didn't work.
What do you think i should do in this case.

Regards
Ajinkya

Please take a look at this code and tell me if I am wrong on logic part.

[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Data.SqlClient;

namespace WindowsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    //public string s;
    private void button1_Click(object sender, EventArgs e)
    {
        //try
        //{
            string goog = "Blackgold";
        //IPAddress[] addresslist = Dns.GetHostAddresses(goog);

            string vip = System.Net.Dns.GetHostEntry(goog).AddressList[0].ToString();
            string strr = "Data Source=" + vip + " ;Network Library = DBMSSOCN;Initial Catalog=MIS;Integrated Security=True";
            SqlConnection con1 = new SqlConnection(strr);
            con1.Open();

            if (con1.State.Equals(ConnectionState.Open))
            {

                //try
                //{

                    string qry = "Insert into TestT values('" + textBox1.Text + "','" + textBox2.Text + "')";
                    SqlCommand cmd = new SqlCommand(qry, con1);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("OK!");
                    con1.Close();
                //}
                //catch (Exception ex)
                //{
                //    MessageBox.Show("Application could not establish connection to the server!");
                //    MessageBox.Show(ex.ToString());
                //}
            }

            else
            {
                MessageBox.Show("Application could not establish connection to the server!");
            }
        //}
        //catch (Exception exx)
        //{
            //MessageBox.Show("Application could not establish connection to the server!");
            //MessageBox.Show(exx.ToString());
        //}
    }
}

}
[/CODE]

Please take a look at this code and tell me if I am wrong on logic part.

[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Data.SqlClient;

namespace WindowsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    //public string s;
    private void button1_Click(object sender, EventArgs e)
    {
        //try
        //{
            string goog = "Blackgold";
        //IPAddress[] addresslist = Dns.GetHostAddresses(goog);

            string vip = System.Net.Dns.GetHostEntry(goog).AddressList[0].ToString();
            string strr = "Data Source=" + vip + " ;Network Library = DBMSSOCN;Initial Catalog=MIS;Integrated Security=True";
            SqlConnection con1 = new SqlConnection(strr);
            con1.Open();

            if (con1.State.Equals(ConnectionState.Open))
            {

                //try
                //{

                    string qry = "Insert into TestT values('" + textBox1.Text + "','" + textBox2.Text + "')";
                    SqlCommand cmd = new SqlCommand(qry, con1);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("OK!");
                    con1.Close();
                //}
                //catch (Exception ex)
                //{
                //    MessageBox.Show("Application could not establish connection to the server!");
                //    MessageBox.Show(ex.ToString());
                //}
            }

            else
            {
                MessageBox.Show("Application could not establish connection to the server!");
            }
        //}
        //catch (Exception exx)
        //{
            //MessageBox.Show("Application could not establish connection to the server!");
            //MessageBox.Show(exx.ToString());
        //}
    }
}

}
[/CODE]

Hey people,

I have a simple application which inserts data into database. The database is located on a remote machine.
However this machine(which has SQL) has a router installed. My pc(which has application) can find this machine's
IP address by using a code. Everything is okay till this stage.
Now when I try to insert data into DB it gives me error "No Such Host Found". As these machines are connected through
same router, so i need to ask that do i have switch on internet everytime I try to insert data Or is there any other way
around this problem?

Please help

Thanks and regards
Ajinkya

Hey here's the code i am having problem in.

[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace print
{
public partial class Form1 : Form
{
private PrintDocument printDocument1;
private PrintPreviewDialog printPreviewDialog1;
private PageSetupDialog pageSetupDialog1;

    public Form1()
    {
        InitializeComponent();
        printDocument1 = new PrintDocument();
       printDocument1.PrintPage +=new PrintPageEventHandler(printDocument1_PrintPage);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'mISDataSet.transact1' table. You can move, or remove it, as needed.
        this.transact1TableAdapter.Fill(this.mISDataSet.transact1);

    }

    private void button1_Click(object sender, EventArgs e)
    {

        Form1 fpr = new Form1();
        fpr.Text = dataGridView1.Text;

        fpr.ShowDialog();
        if (fpr.Result > 0)
         {
           PrintGrid = new DataGridViewPrint(printDocument1, dataGridView1, fpr.bBlackWhite);
           PrintGrid.PrintTitle = fpr.bTitle;
           PrintGrid.Title = fpr.Title;
           if (fpr.Result == 1) // Print
            {
              if (printDialog1.ShowDialog() == DialogResult.OK)
               {
                   // The Print method prints the DataGridView without using a print dialog.
                   // Use a PrintDialog when you want to offer the user the ability to choose print settings.
                  printDocument1.Print();
               }
            }
            else if (fpr.Result == 2) // Page setup
            {
              pageSetupDialog1.ShowDialog();
            }
         }
         else if (fpr.Result == 3) // Preview
         {
             printPreviewDialog1.Icon = fpr.Icon;
             printPreviewDialog1.ShowDialog();
         }
     }

     // Specify the output to print by handling the PrintPage event
     // and by using the Graphics included in the PrintPageEventArgs.
    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
           // Print method of DataGridViewPrint class starts the custom DataGridView's printing process.
        e.HasMorePages = PrintGrid.Print(e.Graphics);
    }

}

}
[/CODE]

I get lot of errors in this code. I think there's no 'DataGridViewPrint' ...

Hey guys,

I have got a problem. I have an application that shows data in datagridview.
Now, I want to add 'Print' option in it. I want to it print only those that are
selected. I have tried a code but it didn't help at all. Please suggest me something
about.

Any kind of help is appreciated!

Thank you
Ajinkya

Hey Guys,

I have gotta problem. I want to store data into database(which i can do) from C# application.
Now the thing is every time I insert or update, I want my application to catch that transaction,
create a 'TRANSACTION ID', and store it in table. So that it would be easier for me to update
and delete the data.
Any idea how can I do this?

Thanks
Ajinkya

Hey guys,

I have written a code that could delete
selected row in data grid view. I gives
lots of errors.

Let me paste my code.

[CODE]for (int i = 0; i < dataGridView1.Rows.Count; i++)
{

                    DataGridViewRow dr = dataGridView1.Rows[i];
                    if (dr.Selected == true)
                    {
                        dataGridView1.Rows.RemoveAt(i);

                        cmd.CommandText = "Delete from transact1 where C_ID ='" + i + "'";
                        cmd.ExecuteNonQuery();

                        da.Update(ds, "transact1");
                        MessageBox.Show("Deleted");
                    }

                    con1.Close();
                }[/CODE]

While deleting row it throws exception.
"Connection property not initialized"

I have tried opening connection in different ways
but it didn't help either.
So can anyone tell me what can possibly wrong with
this code?

Thanks
Ajinkya

Hey Guys,

I am now loosing my cool over this problem.
let me paste my code an then i'll explain my problem.

Here's my code :

[CODE] if (rn < ds1.Tables["Company"].Rows.Count-1)
{
rn = rn + 1;
textBox1.Text = ds1.Tables["Company"].Rows[rn].ItemArray[0].ToString();

                SqlDataAdapter da1 = new SqlDataAdapter("Select C_ID from Company where C_NAME ='Germany'", con2);

                da1.Fill(ds1, "Company");

[/CODE]

Here, I have a textbox that should show the id of company that is selected by user from combo box. But somehow it keeps on nudging me error : Object reference not set to instance of an object. I tried all possible ways but couldn't find a way around.
Can anybody of you suggest anything?

thank you
Ajinkya

Hey Mitja,

Thanks a ton for your reply.
That really worked.

Hey, i am sorry to as for more, but there's a catch.

I want to ID to be in the form of 'S1', 'S2'...and so on.
But as in the above code you have declared 'id' as int, hence
after i enter first Id as 'S1', it gives error.
Can suggest some code so that i can rectify this error.
Sorry if I am asking for more.

Thanks again

Hi everyone,

From couple of days i am trying to write a code that would generate Id automatically
and store it in table. I have a table "STU". It has two columns Id and Name.
I have taken a form which has two text boxes and a button.
text box1 is for ID and it is disabled, textbox2 is for name where user has to enter a
name. I want the ID which is generated automatically, to be displayed in textbox1 and then store
it with the name that user has entered in textbox2. If anybody can suggest a code or a logic
that would be great.

thank you
ajinkya

Here 'TT' refers to as table name.
And i also inserted a row and then
tried generating 'ID'. But it didn't
work. Do you have any other way?

Thanks

Hey guys,

I am trying to write down a code for generating 'ID' automatically
and then store it in table. There some errors, i couldn't rectify.

This is my code :

[CODE] int ctr = 1;
int len;

        DataTable dt = new DataTable();
        DataRow dr;
        DataSet ds = new DataSet();

        string code;
        string cde;

        dt = dB1DataSet1.Tables["TT"];
        [COLOR="Red"]len = dt.Rows.Count - 1;[/COLOR]  [COLOR="Green"]//Error : did not declare object instance.[/COLOR]

        dr = dt.Rows[len];
        code = dr["ID"].ToString();
       [COLOR="Red"] cde = code.Substring(1,3)[/COLOR]; [COLOR="Green"]//Error : Start index cannot be greater than length of the string.[/COLOR]

        ctr = Convert.ToInt32(cde);

        if ((ctr <=1) && (ctr < 9))
        {
            ctr = ctr + 1;

            textBox1.Text = "C00" + ctr;

        }
        else if ((ctr >= 9) && (ctr < 99))
        {
            ctr = ctr + 1;
            textBox1.Text = "C0" + ctr;
        }
        else if (ctr >= 99)
        {
            ctr = ctr + 1;
            textBox1.Text = "C" + ctr;
        }

         string qery = "insert into TT values('" + textBox1.Text + "' , '" + textBox4.Text + "')";
            OleDbCommand cmd2 = new OleDbCommand(qery, olcon);

            cmd2.ExecuteNonQuery();

            MessageBox.Show("Company Saved successfully");

            olcon.Close();

    }[/CODE]

Help me to know the reason for these errors. And also if you can suggest alternate code.
that would be great.

Regards
Ajinkya

Hey guys i think i got the answer.
which was very much simple than i had thought.
But still i want you people to check it and tell
that if it works for you.

[CODE] public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    { 

        string myhost = System.Net.Dns.GetHostName();
        string myip = System.Net.Dns.GetHostEntry(myhost).AddressList[0].ToString();
        MessageBox.Show(" "  +myhost+ ""  +myip);
    }

}

[/CODE]

Thanks for replying

Hey guys,

Check out this code.
It gives me errors.
Can you rectify it?

[CODE]public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show(GetIP());
    }
    public string GetIP()
    {
        string strhostname = System.Net.Dns.GetHostByName();
        IPHostEntry iphostinfo = Dns.Resolve(Dns.GetHostByName());
        IPAddress ipad = iphostinfo.AddressList[0];
        return ipad.ToString();
    }
}[/CODE]

[B]Errors :[/B]

Error 1 No overload for method 'GetHostByName' takes '0' arguments

Error 2 No overload for method 'GetHostByName' takes '0' arguments

Error 3 The best overloaded method match for 'System.Net.Dns.Resolve(string)' has some invalid arguments

Error 4 Argument '1': cannot convert from 'System.Net.IPHostEntry' to 'string'

hey munnaz,

thanks for your reply.

Let me paste my code :

[CODE]private void button1_Click(object sender, EventArgs e)
{

        OleDbConnection con = new OleDbConnection(str);

        OleDbCommand cmd = new OleDbCommand();
        for (int i = 0; i < dataGridView1.Rows.Count; i++)
        {
            DataGridViewRow dr = dataGridView1.Rows[i];
            if (dr.Selected == true)
            {
                dataGridView1.Rows.RemoveAt(i);
                try
                {
                    con.Open();
                    cmd.CommandText = "Delete from company where ID=" + i + "";
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }[/CODE]

I tried deleting row through this code but nothing happened.
Can you help me with the code?

Thanks and Regards
Ajinkya

Hey people,

I have a database that is stored on a remote machine.
In my application i have used connection string with
IP address of that remote machine. Now, the problem is
every time the remote machine is turned on it has a new
IP address. Is there any way that i can get that newly
generated IP address stored in connection string automatically
every time i try to connect to database.

Here's my connection string :

[CODE][COLOR="Red"]Data Source=xxx.xxx.xxx.xxx,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
[/COLOR]
[/CODE]

NOTE : Its not a web application.

thanks

Hey guys,

I need a code that would delete the row from not only from
grid view but also from the table.

I am able to delete the row from grid view but its not getting deleted
from table.

Any suggestions on how to do it.

Regards
Ajinya

Hey i got the answer.
I just need to make couple of changes in connection strings.

thanks anyways.

Ciao

I am not good with ASP, so is there another way of doing it?

hey thanks for your reply.

I tried doing it this way.

But neither its showing the selected text nor its
showing the index value of that text.
Here's my CODE. Please let me know if there's something wrong in it.

Form1:

[CODE]public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();

       // forms1 fr2 = new forms1(s1);
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    public string s1;
    public int s2;   

    private void button1_Click(object sender, EventArgs e)
    {
        forms1 fs = new forms1(s1,s2);
        Form2 oj = new Form2(fs);
        oj.Show();

    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        s1 = comboBox1.Text;
        s2 = comboBox1.SelectedIndex;
    }

}
public struct forms1
{
    public string s;
    public int s4;

    public forms1(string s, int s4)
    {
        this.s = s;
        this.s4 = s4;

    }
    public string text()
    {
        return "this was selected"  +  s + "This was number" + s4;
    }
}
[/CODE]

FORM2 :

[CODE]public partial class Form2 : Form
{
forms1 fr;

    public Form2(forms1 ew)
    {
        InitializeComponent();
        fr = ew;
    }

    private void Form2_Load(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {

            fr = new forms1();

            MessageBox.Show(fr.text().ToString());

    }
}[/CODE]

Hey people,

I want to make an application which would be connected to a database.
It would retrieve data make changes and store it in database again. I have
figured on how to make this application. But the real catch is i want database
to be stored on a single machine. How do i make it the way so that it would get
updated from any other machine which is connected to it in either LAN or via wi-fi.

Any ideas?

Thanks

Hey guys,

I have two forms, form1 and form2.
My form1 has a combo box and a button.
Here's form1 code.

[COLOR="Red"][B]Form1[/B][/COLOR]

[CODE] public partial class Form1 : Form
{
bool s;
public Form1()
{
InitializeComponent();
s1 = comboBox1.Text;

    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    public string s1;

    private void button1_Click(object sender, EventArgs e)
    {
        s = true;
        Form2 oj = new Form2(s1);
        oj.Show();
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

}
public struct forms1
{
    public string s;

    public forms1(string s)
    {
        this.s = s;
    }
    public string text()
    {
        return "this was selected" + s;
    }
}[/CODE]

Now the thing is, as you can see i have declared a structure, with the help of this structure i am trying to show, in second form, the value that was selected from combo box.

Here's code for my Form2

[B][COLOR="Red"]Form2[/COLOR][/B]

[CODE]public partial class Form2 : Form
{
forms1 fr;
string ss1;
public Form2(string re)
{
InitializeComponent();
ss1 = re;
}

    private void Form2_Load(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        fr = new forms1(ss1);
        MessageBox.Show(fr.text());

    }
}[/CODE]

The problem here is as structure is declared outside the class in form1, i cannot declare variables for 'combobox.text' in it. And so now, when i click the button
in form2 it shows the text that was declared in struct but not the text that was selected in combo box. So is there any way to display the text of combo box.

NOTE ...

Thanks for your reply.

i haven't written any code yet.
Let me explain you why i need this.

suppose i have two forms; form1 and form2.

on form1 i have 4 buttons. All these buttons open
form2 on click. In form2 i have a data grid view which shows data
of tables([COLOR="Red"]has same name that of button[/COLOR]). Now how do i
put this in form2 that which table to show, unless it([COLOR="Red"]form2[/COLOR]) knows which button was clicked.

(hey sorry if you find this confusing).

Thanks
ajinkya