PDA

View Full Version : سوال: ارتباط Sql Datasource با GridViwe .



khatereha7
چهارشنبه 06 دی 1391, 20:27 عصر
سلام دوستان.
من با استفاده از Sql Datasource از داخل Sql يک StoredProcedure رو فراخواني کردم.
داخل خود Datasource يک قسمتی به اسم Test Query هست که وقتی انتخابش ميکنم اطلاعاتم به درستی لود ميشه.
داخل صفحه وب يک Buuton گذاشتم و ميخوام وقتی انتخاب ميشه ،Datasource من Bind بشه و اطلاعاتم رو داخل يک GridViwe ببينم.
رويداد Datasource.DataBind رو داخل رويداد Click نوشتم .اما وقتی صفحه لود ميشه اين پيغام ها رو ميبينم و اصلا صفحه بالا نمياد.
کسی ميتونه کمکم کنه؟؟؟؟؟:متفکر::ناراحت:


//-------------------------------------------------------------------------------------------------------------
Server Error in '/' Application.

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9591147 System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt) +130 System.String.System.IConvertible.ToInt64(IFormatP rovider provider) +48 System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +361 System.Web.UI.WebControls.Parameter.GetValue(Objec t value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +126 System.Web.UI.WebControls.Parameter.GetValue(Objec t value, Boolean ignoreNullableTypeChanges) +63 System.Web.UI.WebControls.Parameter.get_ParameterV alue() +40 System.Web.UI.WebControls.ParameterCollection.GetV alues(HttpContext context, Control control) +261 System.Web.UI.WebControls.SqlDataSource.CreateRawC acheKey() +510 System.Web.UI.WebControls.SqlDataSource.CreateCach eKey(Int32 startRowIndex, Int32 maximumRows) +14 System.Web.UI.WebControls.SqlDataSource.LoadDataFr omCache(Int32 startRowIndex, Int32 maximumRows) +16 System.Web.UI.WebControls.SqlDataSourceView.Execut eSelect(DataSourceSelectArguments arguments) +342 System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +21 System.Web.UI.WebControls.DataBoundControl.Perform Select() +143 System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +74 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +66 System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

aminmorteza
چهارشنبه 06 دی 1391, 22:06 عصر
سلام فکر کنم شما باید اینجوری بنویسید

GridView.Datasource = SqlDatasource;
GridView.DataBind();

khatereha7
پنج شنبه 07 دی 1391, 16:53 عصر
اين رو هم زدم ولی به بايند کردن گريدم ارور ميگيره.
يعنی کسی نميدونه چطور ميشه حلش کرد؟؟؟

khatereha7
پنج شنبه 14 دی 1391, 00:20 صبح
بچه ها اين مشگل هم حل شد.ميگم که شماها هم مثل من نرید سر کار.داخل asp نمیتونید از هر متدی برای storedprocedure استفاده کنید.من از بین تمام راه حل هایی که تست کردم این جواب داد.:
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = Vg_ConnectionString;
if (sqlConnection.State == ConnectionState.Closed || sqlConnection.State == ConnectionState.Broken)
sqlConnection.Open();
SqlCommand objCommand = new SqlCommand("Sp_UserLogin");
objCommand.Connection = sqlConnection;
objCommand.CommandType = CommandType.StoredProcedure;
objCommand.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = TxtUserName.Text;
objCommand.Parameters.Add("@Password", SqlDbType.NVarChar).Value = TxtPass.Text;
objCommand.Parameters.Add("@Code_Personaly", SqlDbType.BigInt).Direction = ParameterDirection.Output;
//-------------------------------------
objCommand.ExecuteNonQuery();