الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مشكلة فى Funcation البحث عن طريق StoredProcedure

مغلق
بدأه bnitt في 25 يوليو 2007 · 5 رد · 752 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

اخواني كيف امرر اسماء البرميترات فى هذة الFuncation

using System;
using System.Data.SqlClient;
using System.Collections;

namespace SimpleStoredProcedure
{
	/// <summary>
	/// Summary description for SimpleStoredProcedure
	/// </summary>
	public class SimpleStoredProcedure
	{
		private string myConnectionString;
		private SqlConnection Connection;
		private SqlCommand comm;
		private SqlParameter samparam;

		public SimpleStoredProcedure(string ConnectionString)
		{

			myConnectionString = ConnectionString;
			Connection = new SqlConnection(myConnectionString);
			comm = new SqlCommand();

			samparam = new SqlParameter();
		}

		/// <summary>
		/// Executes a StoredProcedure with it's defined parameters
		/// </summary>
		/// <param name="StoredProcedure">Name of the StoredProcedure to execute</param>
		/// <param name="tableName">Name of the table that the StoredProcedure uses</param>
		/// <param name="ParamName">Name of the parameters with it's associated value</param>
		/// <returns>A dataReader object containing the result of the SQL StoredProcedure</returns>
		public DataSet SQLRET(string StoredProcedure, string tableName, params DictionaryEntry[] ParamName)
		{
			comm = new SqlCommand(StoredProcedure);
			comm.CommandType = CommandType.StoredProcedure;

			foreach (DictionaryEntry paramV in ParamName)
			{
				comm.Parameters.AddWithValue(paramV.Key.ToString(), paramV.Value);

			}

			SqlDataAdapter resultDA = new SqlDataAdapter();
			resultDA.SelectCommand = comm;
			resultDA.SelectCommand.Connection = Connection;


			Connection.Open();
			try
			{
				DataSet resultDS = new DataSet();
				resultDA.Fill(resultDS, tableName);
			}
			finally
			{
				Connection.Close();
			}
			return resultDS;
		}
		}
		}

تمرير القيم فى كود vb.net in asp.net

Partial Class Stor
	Inherits System.Web.UI.Page
	Dim SP As New SimpleStoredProcedure
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	 SP.SQLRet("Stor1","Test",("@name))
	End Sub
End Class

السؤال هناك خطا فى تمرير البارميتر وقيمتة كيف امرر قيم params DictionaryEntry واين اضع قيمة Value للبرميترات

SP.SQLRet("Stor1","Test",("@name

تم تعديل هذه المشاركة بواسطة bnitt في 25 يوليو 2007 في 19:33

#2

حسنا رأيت موضوعك في قسم SQL Server تسأل عن عمل Stored Procedure لحذف-اضافة وغيرها ...

ببساطة أخي الكريم الموضوع كالتالي:

في SQL Server الموضوع كالتالي:

INSERT INTO TableName(Field1,Field2,Field3) Values(@Val1,@Val2,@Val3)

حيث تكون قد صرحت عن المتحولات بالسطر التالي قبل كتابه التعليمية لتصبح تعليمة انشاء هذا ال Procedure كالتالي:

Create PROCEDURE Pro

@Val1 as [Type],
@Val2 as [Type],
@Val3 as [Type]

INSERT INTO TableName(Field1,Field2,Field3) Values(@Val1,@Val2,@Val3)

حسنا في الناحية البرمجية سنقوم باستدعاء هذا التابع كما يلي:

SqlConnection Conn = new SqlConnection("Connection String Goes Here ...");
SqlCommand cmd = new SqlCommand (Conn,"Pro");//The name of the Procedure only
Cmd.CommandType=CommandType.StoredProcedure;
Cmd.Parameters.AddWithValue("@Val1" , "The First Value");
Cmd.Parameters.AddWithValue("@Val2" , "The Second Value");
Cmd.Parameters.AddWithValue("@Val3" , "The Third Value");

try
{
	Conn.Open();
	if(Cmd.ExecuteNonQuery()>0)
	{
		//We have Inserted row.
	}
	else
	{
		//Faild due to some resons...
	}
}
finally
{
	Conn.Close();
}
//هي كل القصة

n

#3

اشكرك اخى لكنى اريد ان استخدم Funcatin حتى لا اكرر كتابة الكود مرة اخرى فى كل مرة

والمطلوب الان هو البحث كما فى Funcatin الى سويتها اريد كيفية استدعاء اسماء البرمترات فقط فى الكود للبحث عن سجلات فى قاعدة البيانات

#4

حسنا أنشئ استعلام وضع الباراميترات وبدل أن تضع عنصر SqlCommand ضع عنصر SqlDataAdapter واملأ به DataSet وارجعها للكود واستخدمها أينما يحلو لك.

هل وصلت الفكرة ؟

#5

اشكرك جدا اخى وفهمتك تماما

انا بنيت فانكشن للبحث وهذة صيغتها :-

 public DataSet SQLRet(string StoredProcedure, string tableName, params DictionaryEntry[] ParamName)
		{
			comm = new SqlCommand(StoredProcedure);
			comm.CommandType = CommandType.StoredProcedure;

			foreach (DictionaryEntry paramV in ParamName)
			{
				comm.Parameters.AddWithValue(paramV.Key.ToString(), paramV.Value);

			}
			SqlDataAdapter resultDA = new SqlDataAdapter();
			resultDA.SelectCommand = comm;
			resultDA.SelectCommand.Connection = Connection;
			Connection.Open();
			try
			{

				resultDA.Fill(resultDS, tableName);
			}
			finally
			{
				Connection.Close();
			}
			return resultDS;
		}

المشكلة هنا فى تمرير القيم :-

SP.SQLRet("SP_AddresBook", "AddresBook", "@ID", "@Name", "@Sex")
#6

Dim openWith As New Hashtable()

' Add some elements to the hash table. There are no

' duplicate keys, but some of the values are duplicates.

openWith.Add("Id", "001")

openWith.Add("Name", "Star")

openWith.Add("Sex", "Male")

then :

SP.SQLRet("SP_AddresBook", "AddresBook", openWith)

هذا الموضوع مغلق.

مواضيع مشابهة