private void btnsave_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < itemgrid.RowCount - 1; i++)
{
dru.insertdata("insert into tbl_godown (date,category,product,quantity,MRP,salesrate,margin,Total,vendor,unit)values('" + itemgrid.Rows[i].Cells["Column1"].Value.ToString() + "','" + itemgrid.Rows[i].Cells["Column2"].Value.ToString() + "','" + itemgrid.Rows[i].Cells["Column3"].Value.ToString() + "','" + itemgrid.Rows[i].Cells["Column4"].Value.ToString() + "','" + double.Parse(itemgrid.Rows[i].Cells["Column5"].Value.ToString()) + "','" + Convert.ToDouble(itemgrid.Rows[i].Cells["Column6"].Value.ToString()) + "','" + Convert.ToDouble(itemgrid.Rows[i].Cells["Column7"].Value.ToString()) + "','" + Convert.ToDouble(itemgrid.Rows[i].Cells["Column8"].Value.ToString()) + "','" + Convert.ToDouble(itemgrid.Rows[i].Cells["Column9"].Value.ToString()) + "','" + Convert.ToDouble(itemgrid.Rows[i].Cells["Column10"].Value.ToString()) + "') ");
MessageBox.Show("Insert Successfully");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
なかった、のDataGridViewの名前はitemgridある入力文字列がデータベースにDataGridViewのデータを挿入する正しいフォーマットC#のWinフォームアプリケーションで
private void txtquantity_TextChanged(object sender, EventArgs e)
{
mulfunc();
}
private void txtrate_TextChanged(object sender, EventArgs e)
{
mulfunc();
marginfunc();
}
private void txtMRP_TextChanged(object sender, EventArgs e)
{
marginfunc();
}
/// <summary>
/// margin calculations(sales rate-vendor rate = margin)
/// </summary>
public void marginfunc()
{
try
{
double val1;
double val2;
if (!double.TryParse(txtMRP.Text, out val1) || !double.TryParse(txtrate.Text, out val2))
return;
double val3 = val2 - val1;
// Here you define what TextBox should show the multiplication result
txtmargin.Text = val3.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// quantity * sales rate
/// </summary>
public void mulfunc()
{
try
{
double val1;
double val2;
if (!double.TryParse(txtquantity.Text, out val1) || !double.TryParse(txtrate.Text, out val2))
return;
double val3 = val1 * val2;
// Here you define what TextBox should show the multiplication result
txttotal.Text = val3.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void clear()
{
cmbunit.Text = "";
txtprod.Text = "";
txtquantity.Text = "";
txtMRP.Text = "";
txtrate.Text = "";
txtmargin.Text = "";
txttotal.Text = "";
txtvendor.Text = "";
}
日付形式 – Vijay
をチェックすると、列の一部が文字列ではなく、すべてを文字列(varcharまたはnvarchar)として挿入しています。 – Laazo
あなたはどのデータベースを使用していますか?あなたの「挿入」ステートメントが悪いです。 – jdweng