Dear developers...
I have problem with code... I cant understand where is mistake... here is my code...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace Phon_Imenik
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con = new SqlConnection("data source = .\\sqlexpress;integrated security = true;Initial Catalog = Tel.Imenik");
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand("Insert into Osoba values(@Osoba ID,@Ime, @Prezim,@Adresa,@Telefon,@Mob1,@Mob2,@Mob3) ");
da.InsertCommand.Parameters.Add("@OsobaID", SqlDbType.Int).Value = Convert.ToString(textBox1.Text);
da.InsertCommand.Parameters.Add("@Ime", System.Data.SqlDbType.NVarChar, 50).Value = textBox2.Text;
da.InsertCommand.Parameters.Add("@Prezim", System.Data.SqlDbType.NVarChar, 50).Value = textBox3.Text;
da.InsertCommand.Parameters.Add("@Adresa", System.Data.SqlDbType.NVarChar, 50).Value = textBox4.Text;
da.InsertCommand.Parameters.Add("@Telefon", System.Data.SqlDbType.NVarChar, 50).Value = textBox5.Text;
da.InsertCommand.Parameters.Add("@Mob1", System.Data.SqlDbType.NVarChar, 50).Value = textBox6.Text;
da.InsertCommand.Parameters.Add("@Mob2", System.Data.SqlDbType.NVarChar, 50).Value = textBox7.Text;
da.InsertCommand.Parameters.Add("@Mob3", System.Data.SqlDbType.NVarChar, 50).Value = textBox8.Text;
con.Open();
da.InsertCommand.ExecuteNonQuery();
con.Close();
when I run this code i get a error in line da.InsertCommand.ExecuteNonQuery with message
ExecuteNonQuery: Connection property has not been initialized.
Any one who can hellp me to understand a mistake....