How do I determine which SQLDBType to assign to a parameter depending on the input variable to store in the DB? Is there a GetType equivelant to test with?
If IsNumeric(ParameterValue) Then
Parameter.SqlDbType = SqlDbType.Float
ElseIf IsDate(ParameterValue) Then
Parameter.SqlDbType = SqlDbType.DateTime
ElseIf IsArray(ParameterV...
Using SqlParameters is a recommended method to prevent SQL Injection in your database queries. Where can I find the code/function that internally sanitizes these parameters? I'd like to re-use this function in a custom implementation of mine. I tried to find it using Reflector, but was unsuccessful.
...
I have not worked with parameters in ADO.Net very much. I'm writing a custom .Net data provider (modeled on SqlClient), and have to implement the IsNullable property in my parameter class, which inherits from DbParameter. My data provider will not support stored procedures, so I will only be supporting Input (substitution style) parame...
I have a query that, basically, says this:
SELECT DISTINCT [DB_ID]
FROM [TableX]
WHERE ([ForeignKey]=@ForeignKey);
Once I have this, I return the first DB_ID (there should be only one).
The routine I've written for calling this is in C# so that I can get the database id for any table name, no matter what the DB_ID is named.
Most of ...
I am trying to use a text box input as a SqlParameter but it only goes into DataSelecting when the page first loads. Not after the from is submitted.
Here is the code on the aspx page.
protected void DataSelecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@zip"].Value = ZipBox.Text;
...
Using NUnit and NMock2 I was not able to compare what I thought were the same SqlParameters:
SqlParameter param1 = new SqlParameter("@Id", 1);
SqlParameter param2 = new SqlParameter("@Id", 1);
Assert.IsTrue(param1.Equals(param2)); // This failed
I stumbled across this problem, when trying to test an execution of a method using NMock2...
So here's the deal. In our database, we wrap most of our reads (i.e. select statements) in table valued functions for purposes of security and modularity. So I've got a TVF which defines one or more optional parameters.
I believe having a TVF with defaulted parameters mandates the use of the keyword "default" when calling the TVF like s...
This is kind of a weird one. I'm looking for ideas on how to ask the right question as much as I am an actual solution.
I've got a website and we just had a huge jump in traffic. Now all of the sudden we're getting sql parameter errors left and right. We switched to a new sql server a few weeks ago and everything has been fine but the a...
What I am trying to do is create some arbitrary sql command with parameters, set the values and types of the parameters, and then return the parsed sql command - with parameters included. I will not be directly running this command against a sql database, so no connection should be necessary. So if I ran the example program below, I wo...
how to pass sql parameter as null value in to integer data type variable ?
StockBO sBO = new StockBO();
sBO.Mode = 2;
if (ddcmpanyname.SelectedIndex != 0)
{
sBO.Client_id = Convert.ToInt16(ddcmpanyname.SelectedValue);
}
else
{
sBO.Client_id = Convert.ToInt16...
I want to pass xml document to sql server stored procedure such as this:
CREATE PROCEDURE BookDetails_Insert (@xml xml)
I want compare some field data with other table data and if it is matching that records has to inserted in to the table.
Requirements:
How do I pass XML to the stored procedure? I tried this, but it doesn’t work:[...