C# - Get Column Names From Table Returned From Stored Procedure?
Feb 10, 2011
I have a stored procedure which returns a table. The stored proc is called via a linq datacontext.
It works fine and I get the table back however I really want to also get the title relating to each particular cell returned.
The stored procedure call is like:
var table = DataContext.GetTable().ToList();
So I get a List<GetTable>. The data is fine I just want the column names as well.
View 2 Replies
Similar Messages:
Apr 23, 2010
This may not be the correct place to put this as it is both a stored procedure AND Visual Studio 2008 problem.
I have the following stored procedure:
[Code]....
I have been mokeying around with it because of what is happening. I have a dataset, call it dataset1. I drag this stored procedure onto the dataset. I EXPECT a datatable to appear, instead the data set adds this store procedure to the queries table adapter and sets the exec mode to 'NonQuery' which unless I am very mistaken, means "don't expect a dataset back from this' when in fact you DO expect a dataset back from this.
The SQL server is a Windows 2000 Server running SQL 2000. It has never caused us a moments grief since we set it up oh-so-many years ago.
If I connect to a different database and drag a query into the same dataset I get a datatable as I expect. I cannot see where / how this procedure could be wrong. The query when executed returns exactly the data I expect, in the format I expect (looks like a table, acts like a table in the Query analyzer).
View 3 Replies
Jan 21, 2010
I a function that used a mySQL Data Adapter and inserts a new row.
I want the function to return the value of the auto-incremented column of the updated row.
Public Function addRow(ByVal colA as String, ByVal colB as String) As Integer
Dim dbConnection As New MySqlConnection("server=xxx; user id=xxx; password=xxx; database=xxx; pooling=false;")
Dim dbDataAdapter As New MySqlDataAdapter("SELECT * FROM table", dbConnection)
[Code].....
The "Return..." line doesn't work and don't know what the correct code would be.
View 3 Replies
Jul 6, 2012
my sp return resultset with different column names based on different parameters passed to sp and now i want to show that data in asp.net(c#) gridview so how can i achieve this
View 1 Replies
Mar 6, 2011
I get a single value from a stroed procedure of type float. Even if I change it into Int or decimal in the procedure when I call it from my asp.net appliction with ExecuteScalar I get this error:
Exception Details: System.InvalidCastException: Object must implement IConvertible.
Source Error:
[Code]....
I tried with
Int32 pomalor=(int32)distpostSqlCommand1.ExecuteScalar();
= Convert.ToString(...);
= (String).....
but I always get the same error.
View 7 Replies
Mar 30, 2010
I have a stored procedure 'RoomIfExists' on my sql server (it does work). It takes a string variable for the Room_No and returns either '1' or '2' depending on the result of the query.
[Code]....
I need to know how to run the sp in c#, passing the variable Room_No and then pull the result from it.I am using a data reader.
View 2 Replies
Aug 21, 2010
I'm have on my web page a text search box which I want users to type in there favourite football team and this will display a gridview of the teams with the replica shirts I offer.
This is where I thought about creating a stored procedure to carry out this task.
I looked online for ideas but I not found anything as yet.
View 3 Replies
Sep 10, 2010
I am working on creating a stored procedure that will output a pivot table. In the pivot table will be either the string NULL or a number. How can I reformat this in ASP.NET so the NULL value becomes a blank cell in the gridview and the number (whatever it is) becomes an 'X' ?
View 3 Replies
Aug 3, 2010
I have heard that saving connection strings and stored procedure names in web.config file of our application is not safe. It is a good practice to store the connection string in a config file rather than as a hard coded string in our code and if we need to change it,then it makes our job easier. how to protect our code in web.config?
View 4 Replies
Feb 17, 2010
I have an ASP ListView which I am using to display some pivoted information (across years) in a table. Currently I have the ListView templates defined as:
<LayoutTemplate>
<table id="listViewTable" class="tableData">
<tr class="rowHeader">
[code]...
View 2 Replies
Apr 16, 2010
I am trying to populate table column names into a dropdown list . how can I query using Linq to SQL to just get the list of few Column names ? in a method in DAL which I can use to load in my UI page !!
View 2 Replies
Jul 14, 2010
Actually i'm doing a project on quiz..i created a questions table with fields qno,qdesc,a,b,c,d,answer....then i wrote a store proc to retrieve qno,qdesc,a,b,c,d randomly.SELECT top 5 Q_No,Q_Desc,A_Opt,B_Opt,C_Opt,D_Opt,answers from [dbo].Questions randomrows ORDER BY NEWID() and another store proc to retrieve answers randomly. SELECT top 5 answerst from [dbo].[Questions] randomrows
ORDER BY NEWID()
but finally i'm getting 1st store proc n 2nd store proc randomly...But the answers related to that particular qstn r not matching. how can we retrieve a column present in one stored procedure into another stored procedure
View 2 Replies
Oct 1, 2010
From my ASP.NET application I am calling an INSERT stored procedure, there is a default value for one of the columns in the table that the INSERT procedure places the data into. How do I specify that I want the default value to be used instead? (Or do I have to specify the actual default value in my parameters)
SITUATIONAL TABLE:
Column 1: int
Column 2: string
Column 3: int default -1
SITUATIONAL STORED PROCEDURE
INSERT INTO TABLE
(Column 1, Column 2, Column 3)
VALUES
(?, ?, ?)
SITUATIONAL ASP.NET CODE
create paramter (Column 1, 12)
if (x = 0)
{create parameter (Column 2, "test")}
else
{
create parameter (Column 3, 24)
create parameter (Column 2, DBNull.Value)
}
View 4 Replies
Nov 19, 2010
I recently moved a .net site from one machine to another, now for some reason one of the stored procedures is throwing an exception when attempting to insert!
Exception Details: System.Data.SqlClient.SqlException: An explicit value for the identity column in table 'dbo.tbl_Events' can only be specified when a column list is used and IDENTITY_INSERT is ON
BTW, the column in question does have the identity set to Yes in management studio
I was using originally SQL 2005, now its on SQLexpress 2008
stored procedure:
[code]....
View 8 Replies
Jan 31, 2011
I have one more question. How can I use a column in the stored prcedure and pass it to a parameter in the code above?
Can we access a column like that?
View 23 Replies
Jan 10, 2010
I am trying to filter a column for when the text matches "True" in the column. I am using the following syntax, don't get an error, but it isn't working.
Select ContactID,FirstName,LastName,Officer,Title
from Contacts
Where officer
=
"True"
View 2 Replies
Oct 19, 2010
Using linq2sql, I've seen examples of using stored procedures for insert, update and delete but how can I use a stored procedure for select?
View 4 Replies
Feb 12, 2010
ALTER procedure [dbo].[Sample2]
@Col as nvarchar(1000),
@Value as nvarchar(1000)
[code]...
View 5 Replies
Sep 17, 2010
tbl_salary
salary salperyr hike20 hike20yr
10000.0000 NULL 12000.00 144000.00
12000.0000 NULL 14400.00 172800.00
14000.0000 NULL 16800.00 201600.00
15000.0000 NULL 18000.00 216000.00
18000.0000 NULL 21600.00 259200.00
20000.0000 NULL 24000.00 288000.00
22000.0000 NULL 26400.00 316800.00
in above table salaryper yr (salperyr) has to be modified after caliculation my null values has to be removed and place(salary*12)in one shot.
View 3 Replies
Nov 17, 2010
trying to write a stored procedure to select any 5 random columns from a selected row,this is the query i ve written so far
[Code]....
[Code]....
View 8 Replies
Apr 2, 2010
This is surareddy. i nead some small clarification in the "Stored Procedure"
how to convert the oracle Stored Procedure to sqlserver2005/2008 Stored Procedure.
right now i am enhancing the project that project already developed the oracle Stored Procedure. now our company is using sqlserver 2005/2008.
how to convert the Oracle Stored Procedure to sqlserver 2005 Stored Procedure
View 4 Replies
Dec 9, 2010
Initially, I have tried to use stored procedure. But I changed my mind and preferred to call sql query in codebase with command text. However, it stills tries to find initially-called stored procedure (which is neither called or exists).I think that it is related caching. But I tried it with different browsers it did not work.What might be the reason?
View 4 Replies
Mar 24, 2010
I'm not so familiar with stored procedures but I'm interesting in moving most of my web selects to stored procedures. I'm working with .net based website and all my data access is something like this:
[Code]....
But now I want to improve some process and make tunings. For that I want to use stored procedures, so instead of the "SELECT ...." sentence I'll put stored procedure name. My problem is how to return a table from one.
View 3 Replies
Apr 22, 2010
I am trying to create a stored procedure where I can insert null values in columns that have a foreign key constraint and allow nulls. The columns I am trying to insert nulls into are commentid and imageid. I have created an Insert statement in a stored procedure and I get the foreign key constraint error. Can you tell me how to allow inserting data in the other columns without having to insert anything in the commendid and the imageid?
Here is my exec of the stored procedure that is not working:
[Code]....
[Code]....
View 6 Replies
Mar 23, 2011
i would like to retrieve data from two table, how can i create a temp table and then insert data from two different table.and then use the temp table to join other table in stored procedure.if i want to select same data from two table, how can i select all distinct data from two table into temp table
View 4 Replies