DataSource Controls :: Add Parameters On Dataadapter?
Jun 23, 2010How could I add parameters on dataadapter? I tried
[Code]....
But parameters is unknown for dataadapter.
How could I add parameters on dataadapter? I tried
[Code]....
But parameters is unknown for dataadapter.
public static DataSet GetSubCategories(int category_id)
View 4 Repliesi'm tring to read data from a sql DB, where is email == mystring - then display its name here is the code:
string mystring;
mystring = "email@email.com";//"Welcome " + System.Convert.ToString(Session["user"]);
generalTableTableAdapters.kurtula_generalTableAdapter generals = new
generalTableTableAdapters.kurtula_generalTableAdapter();
generalTable.kurtula_generalDataTable genaraltab = generals.Getgeneral();
foreach (DataRow row in genaraltab.Rows)
{
if (Convert.ToString(row["email"])== user)
{
Label1.Text = System.Convert.ToString(row["name"]);
}
}
as you can see I'm a table adapter but is giving me the following error: i realy dont know what this error means - though i did a simular action using access DB (and it did work), where i had to user the following: using System.Data.OleDb; now because im using SQL DB im using: using System.Data.SqlClient; //sql server
i am having a datatable with 10 rows.
Out of this 10 rows 3 Rows have their RowState as Added, 2 rows as Modified, and 4 as Deleted.
Now i want to use Datadapter's InsertCommand, UpdateCommand and DeleteCommand
Is it possible to update datatable's changes to Database with Single DataAdpater.Update(DataTable) Call.
Means i will call DataAdapter.Update(DataTable) method only once and with this all new added rows should be inserted in database, modified rows should be updated and deleted rows should be deleted from Database.
Im trying to do the batchinsert (bulk) in sqldataadapter using dataset.but somehow its not inserting (even no error as well), i dunno where i went wrong.my coding..
Dim _cmd As New SqlCommand
I am not sure how to do this. I would like to merge the identity back into the dataset.
View 2 RepliesMy code is not updating the sql database. I am definately passing the correct information in to this function, and it runs without errors. If I exec the procedure with the passed in data, it works great. Can someone tell me what is missing?
public DataTable UpdateEmailList(int listId, string connectionString, DataTable EmailList)
{
//DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(null, conn);
SqlCommand cmd = null;
//add
cmd = new SqlCommand("dbo.fp_ServiceAwards_AddEmailToList", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@emailList_id", SqlDbType.Int)).Value = listId;
cmd.Parameters.Add(new SqlParameter("@email_address", SqlDbType.NVarChar, 255, "email_address"));
cmd.Connection = conn;
da.InsertCommand = cmd;
//delete
cmd = new SqlCommand("dbo.fp_ServiceAwards_DeleteEmailFromList", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@emailList_id", SqlDbType.Int)).Value = listId;
cmd.Parameters.Add(new SqlParameter("@email_address", SqlDbType.NVarChar, 255, "email_address"));
cmd.Connection = conn;
da.DeleteCommand = cmd;
try
{
da.Update(EmailList);
}
catch (Exception ex)
{
string msg = ex.Message;
}
conn.Close();
conn.Dispose();
return EmailList;
}
Title says it all. What is the difference between a DataSource and DataAdapter? I'm trying to decide if I should descend from IDataSource or IDataAdapter for code to be shared between Winforms and WebForms and I can't seem to figure out what the difference is other than slightly different ways to use them.
View 1 RepliesI want to issue an INSERT command for an SQL Server table using DataAdapter without first issuing a SELECT command. Could anybody send me lines of code to handle this? Also how do i manage INSERT into selective table columns (I have 10 columns but i only want to update 2 of them)?
View 2 Replieshere is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
I have asked similiar question before where I have two control on the page header says "username" and "gender". User can select both the control or either one and the page will execute searching based on the criteria supplied. So if username supplied
SELECT * FROM [this_table] WHERE username = @username
and if gender supplied
SELECT * FROM [this_table] WHERE gender = @gender
and if both supplied
SELECT * FROM [this_table] WHERE username = @username AND gender = @gender
I know this sounds not very complicated but in my case, I am having like more than 10 controls up there. It is something likeusername, gender, age, date of brith, title, father name, frst name, last name, blur blur blur and it's a lot then I started to lost. if i were to use if else caluse on code-behind and produce query, it would end up writing a lot of if-else and if i use stored procedure (with if-else) then my stored procedure would contains a lot of if-else statement. I am fairly new to this concept and if I'm on the wrong track, please correct me. Is there any better way to save my hair without actually going through each
if-else statement to build the query ?p.s. I'm using GridView and SqlDataSource command to display the result back on .aspx page.
I have webform with a listview control on it that uses 2 date values supplied by the user (via 2 text boxes) to dynamically set date range parameters for the datasource. The user enters two dates and clicks a button that runs the following code that sets the parameters:
[Code]....
This code works the first time the user clicks the button. But if they change the date values and try again, it only returns the result set from the first request. The parameters are not updated to the new values supplied by the user.
I am trying to check whether a username exists in my database before inserting the new row & display a message to the user if it does.
On my SqlDataSource my InsertCommand looks like this:
InsertCommand="IF NOT EXISTS (SELECT * FROM Users WHERE UserName = @UserName) BEGIN INSERT [Users] ([UserName], [FirstName], [LastName], [City], [State], [Country], [CompanyName], [Active], [PasswordHash]) VALUES (@UserName, @FirstName, @LastName, @City,
@State, @Country, @CompanyName, @Active, @PasswordHash) END"
This works as expected: If the username is unique, the row is created.
If the username already exists, the row is not added.
The problem is, if the row already exists, the insert is rejected but the user is not notified.
So my question is, is there a way I can notify the user?
Maybe something like: InsertCommand = "If Not Exists (select....) Begin Insert...Else Notify User Somehow End This is a basic database, I'm not using the built-in membership provider nor will be.
I'm linking a form to sql database, As far as i know for textbox the code will be like this one below in VB:
dashDataSource.InsertParameters.Add("databaseColumName", NameOFTextBox.Text)
But what is the code for a drop down menu for countries list?
I can't see what I've missed
Dim strSQL As String = _
"UPDATE [emailText] SET " & _
"[stdSubjectLine] = @subjLine, [stdBodyText] = @bodyText, " & _
[code]...
I followd Brian Orrell LINQ tutorial for paging/sorting and created a gridview bound to an ObjectDataSource through a method call which gets data from adatabase. My form includes two buttons with a textbox next to each one of them. I need to be able to populatte th egridview depending on the button that was pressed, I cannot figure out how signal my method which button was pressed.
[Code]....
[URL]
I have a ListView that, among other things, in the EditItemTemplate, has a pair of related DropDownList controls, sort of a parent/child relationship. The selected value of the parent is used as a parameter for the SQL Datasource of the child. Outside of a control such as the ListView, this would be easy and I'd simply set up a ControlParameter for the SQL Datasource and life would be good. Within the DataList things are not quite so simple. My plan is to set the parameter of the child in the Selecting handler of its datasource. I have hard coded some values and this works the way I want it to. My problem is getting the "parent" value. I've got two theories on how to get this:
#1, I've tried instantiating the parent DropDownList but it is either not available at this point in the page life cycle or I just don't know the syntax to get at it from within the Selecting handler.
#2, I'm thinking I may have to grab the value from the underlying data for the ListViewRow that I am editing, but again, I do not know the object model well enough to get at those values.
Below is a code sample for option #1. As stated, setting the parameter works, but getting the value of the DropDownList does not.
All control are not listed in dropdown when selecting a control for adding parameter to update query.
View 1 RepliesI need to retrieve data using a date as an input parameter. I created a WhereParameter and passed in a date value that I know to exist in the database, but no data is returned. Heres my code
[Code]....
Ive passed in '02/06/2010' as the date, in the database, the Startdate column has several values of '2010-06-02 13:08:50.503' so I guess its not being found because of the time part. Whats the best way to make sure that I retrieve the correct data ? Im not concerned about the time at all, I just need all rows for 02/06/2010.
getting the Parameters declared in an sql function in the C# code. We can actually get the parameters from a Stored Procedure by giving SqlCommandBuilder.DeriveParameters
Similarly is there any way to get the Parameters from the SQL Function.
Is it possible in SqlDatasource Update command to combine two parameters to make a third?
[Code]....
this is what I need to do Combine First and Last names with a space between.
I'm attempting to use the following parameter value in my data source:
[code]
<asp:Parameter Name="IPAddress" DefaultValue='<%= HttpContext.Current.Request.UserHostAddress %>' />
[/code]
But the string literal "<%= HttpContext.Current.Request.UserHostAddress %>" is being sent to my stored procedure.
http://msdn.microsoft.com/en-us/library/ms178538(VS.80).aspx ?I tried and got error as below, at clicking Update button in detailView
'/CaseExamples' 응용 프로그램에 서버 오류가 있습니다. ==> Server error in application program
ObjectDataSource 'EmployeeDetailsObjectDataSource'에서 매개 변수 (LastName, FirstName, Address, City, Region, PostalCode, original_FirstName, original_LastName, original_Address, original_City, original_Region, original_PostalCode, original_EmployeeID)를 사용하는
네릭이 아닌 UpdateEmployee' 메서드를 찾을 수 없습니다.
This is my first attempt in using table valued parameters in my stored procedures. Please find the scripts down below. The idea is very simple. I'm trying to insert a new product into Products table and if the product has attributes, I'll insert them into ProductAttributes table which is where I use table-values parameters.
I was able to test the stored procedure manually. It's working fine. So the error must be in the C# code but there's not much to it.
Here's the DAL code in C# that calls the stored procedure:
[Code]....
Just in case you need it, here's what my Product object looks like:
[Code]....
And the ProductAttribute object is even simpler:
[Code]....
Here's the SQL scripts to create the tables, stored procedure and user defined table type:
[Code]....
with query parameters in ASP.NET. For example, if I have query:
[Code]....
for parameter @id I intend to use combobox. Everything is just fine with this example, problem begins when I try to use IN clause.What I need is query like this:
[Code]....
[Code]....