TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Lm Martiness
NA
107
8.1k
Inserting data from into SQL using SP C# winform
Jun 13 2020 2:32 AM
Hi everyone.
I am trying to insert data from two forms into SQL. The form 1 contains some textbox and a datagridview , and Form2 contains two textboxes. When the user click button"btnform2", the form two is opened but the form 1 still remains opened. Now i want when user click the button save(form2) , the data to be saved into sql from two forms.
I created a class
public class arka_data
{
public int NR { get; set; }
public int BARKODI { get; set; }
public string EMERTIMI { get; set; }
public int SASIA { get; set; }
public float CMIMI { get; set; }
public float TVSH { get; set; }
public float TOTAL { get; set; }
public float NENTOTALI { get; set; }
public float ZBRITJA { get; set; }
public float TOTALI { get; set; }
public DateTime KOHA { get; set; }
public string KASIERI { get; set; }
public string KLIENTI { get; set; }
public float VLERAETVSH { get; set; }
public float VLERAPATVSH { get; set; }
public int NRATIKUJVE { get; set; }
public float TOTALIPCS { get; set; }
public float VLERATVSHTOTAL { get; set; }
}
And a method using the upper class to collect data
public void mbushe(string[] args)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
arka_data ad = new arka_data();
ad.NR = int.Parse(txtnrfatures.Text);
ad.VLERATVSHTOTAL = float.Parse(textBox1.Text);
ad.BARKODI = int.Parse(dataTable.Rows[i][0].ToString());
ad.SASIA = int.Parse(dataTable.Rows[i][2].ToString());
ad.CMIMI = int.Parse(dataTable.Rows[i][3].ToString());
ad.TVSH = int.Parse(dataTable.Rows[i][4].ToString());
ad.NENTOTALI = float.Parse(txttotali.Text);
ad.ZBRITJA = float.Parse(txtzbritja.Text);
ad.TOTALI = float.Parse(totali.Text);
ad.KOHA = DateTime.Now;
ad.KASIERI = lbluser.Text;
ad.KLIENTI = cmbklienti.Text;
ad.VLERAETVSH = float.Parse(dataTable.Rows[i][7].ToString());
ad.VLERAPATVSH = float.Parse(dataTable.Rows[i][6].ToString());
ad.NRATIKUJVE = int.Parse(lblnumri.Text);
ad.TOTALIPCS = float.Parse(dataTable.Rows[i][5].ToString());
//and finally
Program.dta.Add(ad);
}
}
But in form 2 , there are not passing data from form 1 .
The code i am using to store data
private void button1_Click(object sender, EventArgs e)
{
arka_data ad = new arka_data();
string faturimi = "Metoda e pagesese" + " "+ "KESH;" +"Paguar"+ txtpaguar.Text + " "+ "Kusuri"+ textBox3.Text;
con.Open();
SqlCommand cmd = new SqlCommand("insertfaturimi", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@nrfatures", ad.NR));
cmd.Parameters.Add(new SqlParameter("@klienti", ad.KLIENTI));
cmd.Parameters.Add(new SqlParameter("@pagesa", faturimi));
cmd.Parameters.Add(new SqlParameter("@nentotali", ad.NENTOTALI));
cmd.Parameters.Add(new SqlParameter("@zbritje", ad.ZBRITJA));
cmd.Parameters.Add(new SqlParameter("@totali", ad.TOTALI));
cmd.Parameters.Add(new SqlParameter("@vleratvsh", ad.VLERATVSHTOTAL));
cmd.Parameters.Add(new SqlParameter("@nrartikujve", ad.NRATIKUJVE));
cmd.Parameters.Add(new SqlParameter("@kasieri", ad.KASIERI));
cmd.Parameters.Add(new SqlParameter("@koha", DateTime.Now));
cmd.Parameters.Add(new SqlParameter("@barkodi", ad.BARKODI));
cmd.Parameters.Add(new SqlParameter("@emertimi", ad.EMERTIMI));
cmd.Parameters.Add(new SqlParameter("@sasia", ad.SASIA));
cmd.Parameters.Add(new SqlParameter("@tvsh", ad.TVSH));
cmd.Parameters.Add(new SqlParameter("@cmimi", ad.CMIMI));
cmd.Parameters.Add(new SqlParameter("@totalipcs", ad.TOTALIPCS));
cmd.Parameters.Add(new SqlParameter("@vlerapatvshpcs", ad.VLERAPATVSH));
cmd.Parameters.Add(new SqlParameter("@vleraetvshpcs", ad.VLERAETVSH));
cmd.ExecuteNonQuery();
}
If someone could help me about where i am missing something, that don't make the code work.
Thanks to everyone!
Reply
Answers (
3
)
How do i cancel git commit
Crystal Reports wont load data