قمت بعمل برنامج بلغه سي شارب يقوم بتنفيذ storedprocedure التالي
create PROCEDURE dbo.abdullah
AS
declare @num int
select @num=max(CategoryID)
from Categories
return @num
البرنامج هو
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication34
{
public class Form1 : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlConnection Cn;
private System.Data.SqlClient.SqlCommand Cmd;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.Cn = new System.Data.SqlClient.SqlConnection();
this.Cmd = new System.Data.SqlClient.SqlCommand();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// Cn
//
this.Cn.ConnectionString = "workstation id=FF;packet size=4096;integrated security=SSPI;data source=ff;persis" +
"t security info=False;initial catalog=northwind";
//
// Cmd
//
this.Cmd.CommandText = "dbo.[abdullah]";
this.Cmd.Connection = this.Cn;
this.Cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 40);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 16);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[sTAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Cn.Open();
textBox1.Text=Cmd.ExecuteScalar().ToString();
Cn.Close();
}
}
}
object refernce not set to an instance of an objectعند تنفيذ البرنامج يظهر الخطاء التالي
