|
You can use @ErrCode as output parameter, @ErrCode value can be collected in .aspx.vb or class file by following codes:
Comm.Parameters.Add("@ErrCode", SqlDbType.Int).Direction = ParameterDirection.Output
Comm.ExecuteNonQuery()
dim returnvalue as integer=comm.Parameters("@result").Value
Kumar
|
|
|
|
|
Ok thanks, but what happens if I want to return @ErrCode, or my own error code, for example -1 or a -2, etc, or the ID of the new car?
|
|
|
|
|
I need to create database file(*.mdb) programmatically, how can I do it?
|
|
|
|
|
use CREATE DATABASE as below:
CREATE DATABASE [testDB] ON (NAME = N'test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\AraWorkFlow_Data.MDF' , SIZE = 3, FILEGROWTH = 10%) LOG ON (NAME = N'AraWorkFlow_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\AraWorkFlow_Log.LDF' , SIZE = 1082, FILEGROWTH = 10%)
|
|
|
|
|
|
You are asking how to make an .mdb (which is a MS Access database).
See this post: clickety[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Hello, is it possible to iterate trough all tables in a database with SQL syntax?
My problem is that i would like to programatically have the possibility to make an xml-backup of the entire database to a remote computer. But the number of tables is unknown during design time.
R.
Johan
|
|
|
|
|
You can use following select statement which return no of user tables available in database
select name from sysobjects where type='u'
name column give you table name
Kumar
|
|
|
|
|
There are some system catalogs that can help, but it varies from database vendor to database vendor. If you're using C++ there are some ATL DB client side helpers for this.
Steve S
Developer for hire
|
|
|
|
|
Some databases support INFORMATION_SCHEMA views you can query:
SELECT * FROM INFORMATION_SCHEMA.TABLES
then loop through the results (be sure to look at the field TABLE_TYPE to see what type of table it is
Now select the columns for each table:
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Current table name'
|
|
|
|
|
Perfekt, this one was easy..
THX
|
|
|
|
|
Hi
I am developing a UserControl, I save this user control code to the database, which will be loaded dynamically to the Page.
In my user control code consist of following lines:
<asp:SqlDataSource ID="GetDataFromDatabase" runat="server" ConnectionString="<%$ ConnectionStrings:sConnectionString %>"
SelectCommand="SELECT field_defaultvalue FROM cp_productfields WHERE field_product_id='ProductID' AND field_type='DropDownList' AND field_Control_ID='ddVCAuflag'"
ProviderName="<%$ ConnectionStrings:sConnectionString.ProviderName %>"></asp:SqlDataSource>
At this moment, I am manually puting this data to data
base using "INSERT INTO" statement.
But I get following error:
Incorrect syntax near 'ProductID'.
This is because single quotation mark around ProductID (field_product_id='ProductID').
If I change this single quotation to double quotation (e.g. field_id="ProductID") then this works okay.
But in that scenario, SELECT statement fails while execution.
Can anyone please let me know how can I achieve both successfully?
Thanks in advance.
|
|
|
|
|
Did you try using :
"SELECT field_defaultvalue FROM cp_productfields WHERE field_product_id='" & ProductID & "' AND field_type='" & DropDownList & "' AND field_Control_ID='" & ddVCAuflag & "'"
??
thanks.
|
|
|
|
|
Hi,
I just have a couple of questions on the DAAB:
When using db.AddInParameter and the input parameter is an empty string, does it automatically add DBNull.Value to the coloumn? Or should I rather then create a method that checks for an empty string, if it is empty then add DBNull.Value to that coloumn (if it accepts NULL values).
How to get the returned value and throw an exception to the user? I usually have a @ReturnValue parameter, with ParameterDirection.ReturnValue. I was thinking of not doing it this way but rather something like:
using (dbCommand = db.GetStoredProcCommand(strSProc))
{
db.AddInParameter(dbCommand, "@CarName", DbType.String, objCar.Name);
// Rest of the parameters
IDataReader rdr = db.ExecuteReader(dbCommand);
if (rdr.Read())
{
// Do convertions here of what was returned from the stored procedure
}
}
Please can someone help advise.
Regards,
ma se
|
|
|
|
|
String or any parameter except int accept Null value for empty parameter.
Kumar
|
|
|
|
|
I have the following using block (not all code is displayed):
try
{
using (dbCommand = db.GetStoredProcCommand("sp_GetAllCars"))
{
rdr = db.ExecuteReader(dbCommand);
while (rdr.Read())
{
Car objCar = new Car();
objCar.ID = rdr.GetInt32(0); // Required
objCar.Name = rdr.GetString(1); // Required
// Add Car instance to array
carList.Add(objCar);
}
// Close the reader object
rdr.Close();
}
}
catch (SqlException ex)
{
HandleSQLError(ex, "sp_GetAllCars");
}
finally
{
dbCommand.Dispose();
}
What does the using block close and dispose of, because I am thinking that I am closing uneccessary stuff. I always thought that the using block only closed this that were declared in the brackets like:
using (...only closed what inserted here...)
{
...
}
Please can someone comment.
Regards,
ma se
|
|
|
|
|
Hi
I don't think you need the
ma se wrote: dbCommand.Dispose();
dbCommand.Dispose(); in the finally block because the using block would have released the dbcommand
|
|
|
|
|
Thanks I thought so, but what about db and rdr, must I still close rdr? Doesn't the using block take care of this?
|
|
|
|
|
Hi
i am not completely sure what you are trying to do but i would have implemented your code this way:
try
{
using (dbCommand = db.GetStoredProcCommand("sp_GetAllCars"))
{
rdr = dbCommand.ExecuteReader(); //db.ExecuteReader(dbCommand);
while (rdr.Read())
{
Car objCar = new Car();
objCar.ID = rdr.GetInt32(0); // Required
objCar.Name = rdr.GetString(1); // Required
// Add Car instance to array
carList.Add(objCar);
}
// Close the reader object
rdr.Close();
}
}
catch (SqlException ex)
{
HandleSQLError(ex, "sp_GetAllCars");
}
finally
{
}
you need to close rdr since it has exclusive access to the connection and without closing it, you can not use the underlying connection. at the end of the using, the dbCommand will be release. what i think you might need in the finally is to close the underlying connection. but that also depends on if you are not using the connection else where within the function after the finally block. i generally don't dispose my connections. but i use the Close() option since this will return the connection to the pool rather than releasing all its resources which happens with dispose().
-- modified at 5:31 Wednesday 12th July, 2006
|
|
|
|
|
What do you mean by the underlying connection? Is it the db? Do I have to close/ dispose of this db as well? If so where?
I defined db like this:
// Load the default database
Database db = DatabaseGlobals.GetDefaultDatabase;
|
|
|
|
|
If you use a using for the datbase connection and for the data reader then you don't need the calls to close or dispose, e.g.,
using (SqlConnection cn = new SqlConnection(connectionString))
{
cn.Open();
string text = "spReadCustomers";
SqlCommand command = new SqlCommand();
command.Connection = cn;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = text;
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
int firstNameIdx = reader.GetOrdinal("FirstName");
int lastNameIdx = reader.GetOrdinal("LastName");
string firstName = reader.GetString(firstNameIdx);
string lastName = reader.GetString(lastNameIdx);
}
}
}
Kevin
|
|
|
|
|
Hi,
When updating a record in the database, for example, is it wise (or good practice) to always do a check to see if the record exists in the stored procedure?
Please can someone comment.
Regards,
ma se
|
|
|
|
|
Checking the record in the procedure for update is always secure. It doesn't take any extra overhead in your program but it is additional as well as perfect checking fot data concurrency
Kumar
|
|
|
|
|
how to write update SQL statement in order to remove all underline in my data for each field, example:
"HIGH COST___" change to "HIGH COST" which is remove the underline for all data..
Thanks
angela
|
|
|
|
|
Update table1 set col1 = replace(col1,'_','')
--
Don't take life seriously because you can't come out of it alive.
-Warren Miller
(From Monty2[^] bio)
|
|
|
|