Monday, August 19, 2013

Lab 3 - Intro to ADO.NET SQL Objects and Stored Procedure In Urdu


Lab 3 - Intro to ADO.NET SQL Objects and Stored... by programinurdu

10 comments:

  1. Aasalam O Alaikum..!!

    :- Javed Bhai maine is video se dekh ke same as it is code likha hai apne pass same to same...

    But ek error deraha hai jab main button pe click kar raha hoon ("Object reference not set to an instance of an Object ")

    Please help me!!!!

    My Code is here :::

    try
    {
    string ConnectionString = ConfigurationManager.ConnectionStrings["employeedb"].ConnectionString;
    SqlConnection Connection = new SqlConnection(ConnectionString);

    SqlCommand Command = new SqlCommand("AddNewRecord", Connection);
    Command.CommandType = CommandType.StoredProcedure;

    Command.Parameters.Add("@EmployeeId", SqlDbType.NVarChar, 8).Value = EmployeeIDTextBox.Text;
    Command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = FirstNameTextBox.Text;
    Command.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = LastNameTextBox.Text;
    Command.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = EmailTextBox.Text;
    Command.Parameters.Add("@Telephone", SqlDbType.NVarChar, 50).Value = TelephoneTextBox.Text;

    Connection.Open();
    Command.ExecuteNonQuery();
    Connection.Close();

    MessageBox.Show("New Employee is added successfully!!!");
    }

    catch(Exception ex)
    {
    MessageBox.Show("Error: " + ex.Message);
    }

    ReplyDelete
    Replies
    1. The code seems to be fine. This code may not have problem with it. Check the code before it. You may have missed creating an object.

      Delete
    2. How to create Object ???

      Delete
    3. Please give me solution..!!!

      Delete
    4. I don't know what is your code ... the code above is fine ... but if you are using a class in the code ... let's say Employee .. then to create an object ... write code "Employee employee = new Employee()" ....

      Delete
  2. This is my full Code :::

    Find an error from this code & tell me the Solution of it please bro :)

    Code is ::

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Configuration;



    namespace CSharp_ADO.NET_Employee
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void AddNewEmployeeButton_Click(object sender, EventArgs e)
    {
    try
    {
    string ConnectionString = ConfigurationManager.ConnectionStrings["employeedb"].ConnectionString;
    SqlConnection Connection = new SqlConnection(ConnectionString);

    SqlCommand Command = new SqlCommand("AddNewRecord", Connection);
    Command.CommandType = CommandType.StoredProcedure;

    Command.Parameters.Add("@EmployeeId", SqlDbType.NVarChar, 8).Value = EmployeeIDTextBox.Text;
    Command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = FirstNameTextBox.Text;
    Command.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = LastNameTextBox.Text;
    Command.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = EmailTextBox.Text;
    Command.Parameters.Add("@Telephone", SqlDbType.NVarChar, 50).Value = TelephoneTextBox.Text;

    Connection.Open();
    Command.ExecuteNonQuery();
    Connection.Close();

    MessageBox.Show("New Employee is added successfully!!!");
    }

    catch(Exception ex)
    {
    MessageBox.Show("Error: " + ex.Message);
    }
    }
    }
    }

    ReplyDelete
  3. I stop to watch more Tutorials of Database because i am stuck in this Tutorial..!!! Please make a solution ..

    ReplyDelete
    Replies
    1. there is no problem in the code ... It looks alright ... Research online and you will find the solution ...

      Delete
  4. I researched alot ..!! But didn't get a Single SolutioN ...

    ReplyDelete
  5. Salam Dear,

    i get the error message after clicking on add new employee. "Error: Object reference not set to an instance of an object".

    Please help me,

    ReplyDelete