Click here to Skip to main content
14,545,256 members

Comments by Member 12764477 (Top 4 by date)

Member 12764477 24-Oct-16 6:32am View
   
I have database with some columns & one column name as 'status' its data type is 'bit' --containing value=true/false/null ..
in run time it is displaying true only but i want to show it as used and false & null both should display as unused (true--replace used
false&null -- replace unused)
my code is like
private void button6_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=AMULYA-PC;initial catalog=barcode;integrated security=true";
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(@"select tblBarcodeTest1.Time,tblBarcodeTest1.Shift,tblBarcodeTest1.InitialCount,tblBarcodeTest1.FinalCount,tblBarcodeTest1.BarcodeName,tblBarcodeTest1.Machine,tblBarcodeTest1.Date,tblBarcodeTest1.Code,tblBarcodeTest1.status,Table_1.Cut_Roll_Code,Table_1.[Ply Width],Table_1.Percentage from tblBarcodeTest1 LEFT JOIN Table_1 ON tblBarcodeTest1.code=Table_1.[Cutting Angle] ", con);
DataSet dt = new DataSet();

sda.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = dt.Tables[0];


foreach (DataColumn col in dt.Tables[0].Columns)
{
dataGridView1.Columns.Add(col.ColumnName, col.ColumnName);
dataGridView1.Columns[col.ColumnName].DataPropertyName = col.ColumnName;
}
dataGridView1.CellFormatting += dataGridView1_CellFormatting;
dataGridView1.CellParsing += dataGridView1_CellParsing;

}
i used another code but i got error at tryparse

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "status")
            {
                bool Used;
                bool.TryParse(e.Value.ToString(), out Used);
                if (Used)
                    e.Value = "Used";
                else
                    e.Value = "Unused";
             
            }
        }

can anybody help me, am new to this C#.net
thanks..
Member 12764477 30-Sep-16 2:56am View
   
this is that error:An unhandled exception of type 'System.InvalidCastException' occurred in System.Data.dll

Additional information: Unable to cast object of type 'System.Int32' to type 'System.String'.


actually textbox2 & 14 are the 1st and 2nd tables of 1st column so while it is reading the value i got error??
if i remove textbox14 to 19 then it will execute upto 13th textbox ...
Member 12764477 29-Sep-16 3:32am View
   
I have 2tables in sql database , i want to display 2 tables data in textbox's & taking one column as reference...here are the code

private void button5_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Initial Catalog=barcode");
SqlCommand cmd = new SqlCommand("select * from tblBarcodeTest1 LEFT JOIN Table_1 ON tblBarcodeTest1.code=Table_1.[Cutting Angle] where code like '" + textBox6.Text + "'", con);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter();
SqlDataReader red = cmd.ExecuteReader();
while (red.Read())
{
textBox2.Text = Convert.ToString(red[0].ToString());
textBox2.Text = Convert.ToString(red[1].ToString());
textBox3.Text = red.GetString(2);
textBox4.Text = red.GetString(3);
textBox1.Text = red.GetString(5);
textBox5.Text = red.GetString(4);
textBox7.Text = Convert.ToString(red[6].ToString());
textBox9.Text = Convert.ToString(red[7].ToString());
textBox8.Text = Convert.ToString(red[8].ToString());
textBox10.Text = Convert.ToString(red[9].ToString());
textBox11.Text = Convert.ToString(red[10].ToString());
textBox12.Text = red.GetString(12);
textBox17.Text = Convert.ToString(red[11].ToString());
textBox13.Text =Convert.ToString(red[13].ToString());
textBox14.Text = red.GetString(0);
textBox15.Text = red.GetString(1);
textBox16.Text = Convert.ToString(red[2].ToString());
textBox18.Text = Convert.ToString(red[3].ToString());
textBox19.Text = red.GetString(4);
}
con.Close();
}

getting error at textbox14 and after remaining boz it is 2nd table data...
can anybody help me..
Member 12764477 29-Sep-16 0:49am View
   
i have changed my code as

private void button5_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Initial Catalog=barcode");
SqlCommand cmd = new SqlCommand("select * from tblBarcodeTest1 LEFT JOIN Table_1 ON tblBarcodeTest1.code=Table_1.[Cutting Angle] where code like '" + textBox6.Text + "'", con);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter();
SqlDataReader red = cmd.ExecuteReader();
while (red.Read())
{
textBox2.Text = Convert.ToString(red[0].ToString());
textBox2.Text = Convert.ToString(red[1].ToString());
textBox3.Text = red.GetString(2);
textBox4.Text = red.GetString(3);
textBox1.Text = red.GetString(5);
textBox5.Text = red.GetString(4);
textBox7.Text = Convert.ToString(red[6].ToString());
textBox9.Text = Convert.ToString(red[7].ToString());
textBox8.Text = Convert.ToString(red[8].ToString());
textBox10.Text = Convert.ToString(red[9].ToString());
textBox11.Text = Convert.ToString(red[10].ToString());
textBox12.Text = red.GetString(12);
textBox17.Text = Convert.ToString(red[11].ToString());
textBox13.Text =Convert.ToString(red[13].ToString());
textBox14.Text = red.GetString(0);
textBox15.Text = red.GetString(1);
textBox16.Text = Convert.ToString(red[2].ToString());
textBox18.Text = Convert.ToString(red[3].ToString());
textBox19.Text = red.GetString(4);

}
con.Close();
}

but getting error at textbox14 and remaining because it is 2nd table database record, how can i show 2tables records at a time in textbox's