Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have Gridview in my Form, If i click button on the Gridview I get Column value of Focused Row and Try to use that Value in next Form. But in that new form error shown like this
C#
public partial class New_Invoice : DevExpress.XtraEditors.XtraForm
   {

       string getOper = "A";

       public New_Invoice()
       {
           InitializeComponent();
       }

       public New_Invoice(string oper, int invoiceno)
       {
           // TODO: Complete member initialization

           textEdit5.Text = invoiceno.ToString(); // error shown in this line
           textEdit5.Visible = false;
           getOper = oper;
       }

Whats wrong in my code ?
Posted
Updated 4-Nov-19 22:18pm
Comments
Thomas ktg 6-Nov-13 6:04am    
What is invoiceno? Does it bring any value or just gives null value? Check that too.
srihari1904 6-Nov-13 6:33am    
it bring value from previous Form <pre lang="c#">private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
string oper = "A";

New_Invoice frm = new New_Invoice(oper, Convert.ToInt32(gridView1.GetFocusedRowCellValue("invoive_number")));
frm.Show();
gridView1.RefreshData();
}</pre>

1 solution

You haven't constructed the controls yet!
Either call InitializeComponent inside all your constructors, or reference the default constructor that does have it first by using construction chaining:
C#
public partial class New_Invoice : DevExpress.XtraEditors.XtraForm
    {

        string getOper = "A";

        public New_Invoice()
        {
            InitializeComponent();
        }

        public New_Invoice(string oper, int invoiceno) : this()
        {
            // TODO: Complete member initialization

            textEdit5.Text = invoiceno.ToString(); 
            textEdit5.Visible = false;
            getOper = oper;
        }
 
Share this answer
 
Comments
srihari1904 6-Nov-13 6:28am    
Hi OriginalGriff,
Now I changed error not shown but it shown Form with Empty Fields means it wont took Column value i think so ?
OriginalGriff 6-Nov-13 6:39am    
Show the actual code you are using!
srihari1904 6-Nov-13 6:59am    
private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
string oper = "A";

New_Invoice frm = new New_Invoice(oper, Convert.ToInt32(gridView1.GetFocusedRowCellValue("invoice_number")));
frm.Show();
gridView1.RefreshData();
}
this code in form 1 and this code in Form 2

public partial class New_Invoice : DevExpress.XtraEditors.XtraForm
{

string getOper = "A";



public New_Invoice()
{
InitializeComponent();
}

public New_Invoice(string oper, int invoive_number)
: this()
{
// TODO: Complete member initialization
//this.oper = oper;
//this.p = p;
textEdit5.Text = invoive_number.ToString();
textEdit5.Visible = false;
getOper = oper;
}
private void New_Invoice_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Srihari/OrionSystem.accdb");

int i = Convert.ToInt32(textEdit5.Text);

OleDbCommand da = new OleDbCommand("select * from invoice_top where invoice_number='" + i + "' ", con);
con.Open();
OleDbDataReader reader = da.ExecuteReader(); // now error shown as "Data type mismatch"
while (reader.Read())
{

textEdit12.Text = reader.GetString(1);
textEdit13.Text = reader.GetString(2);
textEdit4.Text = reader.GetString(3);

textEdit1.Text = reader.GetString(5);
textEdit2.Text = reader.GetString(6);
textEdit3.Text = reader.GetString(7);


}

con.Close();
}
OriginalGriff 6-Nov-13 7:18am    
Well, I'm not that surprised you get "data type mismatch" - try this instead:
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Srihari/OrionSystem.accdb");

int i = Convert.ToInt32(textEdit5.Text);

OleDbCommand da = new OleDbCommand("SELECT * FROM invoice_top WHERE invoice_number=@IN, con);
da.Parameters.AddWithValue("@IN", i);
con.Open();
OleDbDataReader reader = da.ExecuteReader();
And (assuming your invoice_number column is an integer) that should work - it is a bad idea to concatenate strings to form SQL commands, it leaves you open to SQL Injection attacks. Always use parametrised queries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900