using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
///
/// Summary description for DataClass
///
///
public class DataClass
{
public DataClass()
{
}
///
/// return rows depend on position
/// if you need 10th to 20th you need to pass start=10 and end=20
///
/// database start position of one row
/// database end position of one row
///
public string GetAjaxContent(int start, int end)
{
string result = string.Empty;
//adding sp params with values in Dictionary entry.
Dictionary keyValPair = new Dictionary();
keyValPair.Add("@start", start);
keyValPair.Add("@next", end);
DBHelper DBHelper = new DBHelper();
//passing the Stored Procedure name and keyvalue pair
DataTable dataTable = DBHelper.GetTable("spuserdata", keyValPair);
if (dataTable.Rows.Count > 0)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
result += string.Format(@"
", dataTable.Rows[i][0].ToString(), dataTable.Rows[i][1].ToString(), dataTable.Rows[i][2].ToString());
| {0} | {1} | {2} |
}
}
//this string is going to append on Datalist on client.
return result;
}
///
/// function to bind data on page load
///
///
public DataTable FirstTenRecords()
{
Dictionary keyValPair = new Dictionary();
keyValPair.Add("@start", 0);
keyValPair.Add("@next", 10);
DBHelper DBHelper = new DBHelper();
DataTable dataTable = DBHelper.GetTable("spuserdata", keyValPair);
return dataTable;
}
}
///
/// return sqlconnection string formweb.config file
///
public class Provider
{
public static SqlConnection GetConnection()
{
// return new SqlConnection(ConfigurationManager.AppSettings["conn"]);
return new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
}
}
///
/// Data layer
///
public class DBHelper
{
public DBHelper()
{
}
public DataTable GetTable(string SPName, Dictionary SPParamWithValues)
{
DataTable dataTable = new DataTable();
//SqlCommand cmd;
//SqlDataAdapter adapter;
//SqlConnection conn;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter adapter = new SqlDataAdapter();
conn = Provider.GetConnection();
conn.Open();
//open DB connection
cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = SPName;
foreach (KeyValuePair paramValue in SPParamWithValues)
{
cmd.Parameters.AddWithValue(paramValue.Key, paramValue.Value);
}
adapter = new SqlDataAdapter(cmd);
adapter.Fill(dataTable);---Procedure or function spuserdata has too many arguments specified.
return dataTable;
}
}
here is my stored procedure ,as for i know this error is because when we are specifying more parameters in your c# code than our stored procedure accepts..but i dont understand what are the extra parameters which i add
and here is my stored proc ::
and here is my stored proc ::
create proc spuserdata
@id int
AS
select decription,url from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id
where tb_userlogin.id=@id
how an i resolve this
Thnaks and Regards
how an i resolve this
Thnaks and Regards
Jaganathan BantheswaranPosted Oct 4, 2013, 2:20 PM
You need to pass int value to your SP. But the SessionID is alphanumeric value, so conversion is failing.
Change the SP's @id parameter to nvarchar. or if the @id should be int, then pass correct int to SP.
aditya immadiPosted Oct 3, 2013, 1:20 PM
Thanks and Regards
Jaganathan BantheswaranPosted Oct 2, 2013, 3:25 AM
Try in this way
Begin
End
aditya immadiPosted Oct 1, 2013, 3:49 PM
i tried it but it says the same old error
Thanks and Regards
Jaganathan BantheswaranPosted Oct 1, 2013, 2:37 AM
{
using (var comd = new SqlCommand(spuserdata, con))
{
cmd.CommandType = CommandType.StoredProcedure;
foreach(var keyValue in SPParamWithValues)
{
cmd.Parameters.Add(keyValue.Key, SqlDbType.Int).Value = keyValue.Value;
}
using (var da = new SqlDataAdapter(comd))
{
da.Fill(table);
}
}
Before passing comd to SqlDataAdapter, add the parameters and try.
aditya immadiPosted Sep 30, 2013, 4:57 PM
i just cahnges my code like this
using(var con =Provider.GetConnection() )
using (var comd = new SqlCommand(spuserdata, con)) using (var da = new SqlDataAdapter(comd))
{
cmd.CommandType = CommandType.StoredProcedure;
foreach(var keyValue in SPParamWithValues)
{
cmd.Parameters.Add(keyValue.Key, SqlDbType.Int).Value = keyValue.Value;
}
da.Fill(table);
}
it works fine but now it says expects @id which was not supplied .actuallly i wote a simle procedure like this
ALTER proc [dbo].[spuserdata]
@id int
AS
select decription,url from tb_userdata inner join tb_userlogin on tb_userdata.uidfromtb1=tb_userlogin.id
where tb_userlogin.id=@id
i thoght it was fine.what is wrong with my procedure .can you please help me
and i'm getting curent user id using this
string id = System.Web.HttpContext.Current.Session.SessionID;
Thanks and Regarrds
Jaganathan BantheswaranPosted Sep 29, 2013, 1:48 AM
The above code will work...
You have used the empty cmd object instead of comd.
aditya immadiPosted Sep 28, 2013, 8:33 AM
Thanks and Regards
Jaganathan BantheswaranPosted Sep 27, 2013, 11:48 PM