Hello there I am trying to enter database records from window Form
design and programmed using MS visual C#
and it approved and entered database using an other Window Form
and I call the child Form
using showDialog
, I tried to make it entering to and sending thde data using string array and send it
as following
public string[] cashg1
{
get { return dt; }
set { dt = value; }
}
public void Entering(){
form2.ShowDialog();
string[] inputs = new string[10];
DateTime Date = DateTime.Today;
inputs[0] = numb.Text;
inputs[1] = comboBox1.SelectedText;
inputs[2] = owner.Text;
inputs[3] = curency.Text;
inputs[4] = curncyval.Text;
inputs[5] = Depet.Text;
inputs[6] = cridet.Text;
inputs[7] = Convert.ToString(Date);
inputs[8] = note.Text;
form2.addingdata(inputs);
cashg1 = inputs;
}
public void Entring_to database(){inputs = new string[10];
using (SqlConnection connection = new SqlConnection(connectionString))
{
DateTime Date = DateTime.Today;
try
{
SqlCommand cmd = new SqlCommand("INSERT INTO Accont(Account_ID,Account_Name,Owners,Curency,Curncytype,Depet,Credet_devet,Date,Note) VALUES ( @@AccountID, @AccountName, @Owner, @Curncy,@Curncytype,@Depet,@Cridetdevet,@Date,@Note)");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@@AccountID", Convert.ToInt32(inputs[0]));
if (String.IsNullOrEmpty(inputs[0]))
inputs[0] = "323";
cmd.Parameters.AddWithValue("@AccountName", Convert.ToString(inputs[1]));
if (String.IsNullOrEmpty(inputs[1]))
inputs[1] = " ";
cmd.Parameters.AddWithValue("@Owner", inputs[2]);
cmd.Parameters.AddWithValue("@Curncy", inputs[3]);
cmd.Parameters.AddWithValue("@Curncytype", inputs[4]);
cmd.Parameters.AddWithValue("@Depet", inputs[5]);
cmd.Parameters.AddWithValue("@Cridetdevet", inputs[6]);
cmd.Parameters.AddWithValue("@Date", Date);
cmd.Parameters.AddWithValue("@Note", inputs[7]);
connection.Open();//Owner
cmd.ExecuteNonQuery();
}
catch (Exception ee)
{
MessageBox.Show("Error :" + ee.Message);
}
}
}
}
I enter my data using this Form
:
when I clicked conforming button to enter the data in
datagridview
After conforming the data must enter the database but It dosenot enter and gives my this error
thank you for helping