.Net Application for Creating SP's in SQl - sql-server-2008

I want to create a Dot net application and provide an environment to a user may be Multiline Text box, where user can Paste the predefined SP and Execute. After execution this Sp should be created in DB
Any ideas are invited..

I assume you want to do thid for a internal support application or something like that, not to the end-user, right?
Anyway, you need to be more specific, but the way you would create a procedure doesnt differ the way you would run a insert statment for example.
Simple example:
SqlConnection objConnection = new SqlConnection(your_connection_string);
SqlCommand objCommand = new SqlCommand(tbProcedureCode.text, objConnection);
objCommand.CommandType = CommandType.Text;
objConnection.Open();
objCommand.ExecuteNonQuery();

Related

Using a record set to generate new tables in ACCESS

I am using an ACCESS database to generate reports on a relatively big dataset. As I don't want to wait eternally and also ACCESS has certain size limitations, I execute a complex sql query on my server.
Now I would like to use the result of this complex sql query inside ACCESS to do some final stuff and then display in a form.
I know how to connect ACCESS directly to database tables, I also know how to work from there. But here I have a gap: I have a SQL with some few thousand lines and receive the result as recordset. How to make ACCESS accepting this in it's own architecture?
Dim SQL As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
'SQL query
SQL = " SELECT something quite complex and long"
Set conn = New ADODB.Connection
conn.ConnectionString = "my great server"
conn.Open
Set rs = New ADODB.Recordset
rs.Open SQL, conn
'--- here is my personal gap ---
conn.Close
If your "very complex" SQL code is a stored procedure - you can execute that and return results from it using a pass through query. See here Two ways to execute a Stored procedure in VBA, Which one is better?
If it's a View you can simply link to the view, just like a table.
create a passthru query (or a normal one) with your complex request and save it
create a Make Table Access query that basically contains
select * from myComplexPTQ into myLocalTable
done
If you use normal query rather than passthru, and you find it slow, I suggest you give a look at http://allenbrowne.com/QueryPerfIssue.html

Visual Basic 2010: How to check if data is already in the SQL database?

I'm using Microsoft Visual Basic 2010 Express and SQL Server 2008. I already connected the database I created and managed to input data on in. Im making a very simple registration system where I only put a idNumber and the password. The problem is I have to make the system detect whether the idNumber was already registered then executes a statement.
Imports System.Data.SqlClient
Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=MYDATASOURCE;Integrated Security=True")
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
cmd.Connection = cn
cn.Open()
'this is where to put the code the search the database i think..
cn.Close()
Ive been looking for days and it seems like vb.net is mostly used and answered but I have to use visual basic. I have no idea what code to put in there to read the database. I do think like c++ I have to retrieve the data and declare in on a variable then that is when I search it.
I can provide you brief guidelines, but you need to do due diligence to accomplish this.job.
Write a stored procedure IsIdNumberExists that will check whether a idNumber exists in database tablet. Something like this....
var #recCount
Select #recCount = count(1) from yourTable where idNumber=#inputidNumber // pass it from UI
if #recCount=0
return false
return true
2 In your C# code, pass StoredProcedure name to cmd object.
3 Create a SqlParameter and attach it to cmd object
4 Execute cmd.ExecuteNonQuery();
5 Get the return boolean object in C# and decide accordingly.

Programming for MySql and MSSql in VB.NET

I have a program written in VB.NET that as part of its function requires the use of a number of database classes.
At the moment the classes are programmed specifically to use objects originating from System.Data.SqlClient and classes such as SqlConnection, SqlCommand, SqlParameter and SqlDataAdapter are used.
My aim is to use the analogous classes from Mysql.Data.MySqlClient (obtained via the Connector/Net download on the MySQL site). These for example would be: MySqlConnection, MySqlCommand, MySqlParameter and MySqlDataAdapter.
Is there some way in the code that I could maybe specify an abstract version of the classes (something like AbstractSqlCommand, AbstractSqlParameter) and be able to pick the correct implementation between SqlCommand and MySqlCommand based on the use of some other config variable.
Dim command As New AbsSqlCommand(sql, connection)
For Each p As AbsSqlParameter In param
command.Parameters.Add(p)
Next
Dim timeout As Integer = 3000
command.CommandTimeout = timeout
Try
connection.Open()
Catch
Throw New Exception("Connection failed")
End Try
Dim Adapter As New AbsSqlDataAdapter(command)
Adapter.Fill(table)
Return table
So in the case above some kind of global or configuration variable could be ussed to differentiate between whether AbsSqlCommand is actually used as a MySqlCommand or a SqlCommand [MSSQL] without the need for having to recode every instantiation of these objects to suit the particular database platform.
This is really a broad question that will be best answered by a full article like this, but look at
System.Data.Common Namespace
The classes in System.Data.Common are intended to give developers a
way to write ADO.NET code that will work against all .NET Framework
data providers.
Well you could have two linq to sql instances (there is no constraint on the number of instances and calsses there in), but I have no experince of using linq2sql with MySQL so I dont know how well it works. Id be inclined to set up a test project add a linq2sql setofdatatclesses and try to connect to a MySQL database, see what happens)

VB.NET Datatable to Mysql

I'm creating an application which allows you to manage various data. The application is designed to work in a network, and thus in multi-user. For this reason I decided to trust the Datatable.
I have a class created by me for the management of operations MYSQL Database but now I still can not create a streamlined process to send the datatable to MySQL database.
Currently I am so
Dim SQLStm As String
'variable for sql query
Dim SQLManager As New ER.DB.ERMysql
For Each Riga In Datatable.Rows
'example query
SQLStm = "INSERT INTO test(Name,Phone)VALUES(Riga("Name"),Riga("Phone"))"
Try
Dim CMD As New MySqlCommand
CMD.Connection = connection
CMD.CommandText = SQLStm
CMD.ExecuteNonQuery()
Catch ex As Exception
End Try
Next
End Sub
or skim all the rows and gradually sending to the database. There is a better way to accomplish this?
Thanks to all
I would say the best way to do this would be via XML. Convert the datatable to xml format and pass it through to a procedure which accepts an XML. This saves the process from running once per every line within a datatable, and it is all done in one go. The current way you are doing this would not scale well for large data sets, but XML would scale far better.
instead performing a db insert for each row, build the whole query string first and then perform it as one large INSERT command. It's much faster.

Using more data sets in Report Server from one stored procedure

I am deploying a lot of report lately.
And so to I kept code and version clear and understanding,
Ill like to have one stored procedure per report.
Mostly time I need more data sets for one reports.
Is there possibility to I have more then one data set in report SSRS for calling only one stored procedure for that report.
(I am using remote reports hosted on Sql Report Server 2008 ).
I uses familiar Issue whit sample console application for creating multiple CSV files from SQL using one stored procedure.
snipes of code looks something like this:
SqlConnection conn = new SqlConnection(strConn);
SqlCommand command = new SqlCommand("sp_ado_pos_data", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("#skl_id", SqlDbType.Int).Value = 158;
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
for (int i = 0; i < ds.Tables.Count; i++)
{
string datoteka = (string.Format(#"{0}tablea{1}.csv", direktorij, i));
DataTable tabela = ds.Tables[i];
//Here I fill datasets with multiple results from one stored proc.
CreateCSVFile(tabela,datoteka );
Console.WriteLine("GeneriĊĦem tabelu {0}", datoteka);
}
It appears that this isn't possible with standard reports presented through the default report viewer - SSRS ignores all but the first result set from a multi result-set source.
However, based on this article, it appears that it is be possible in stand-alone reports (.rdlc extension). I'm not sure whether this means that, with a custom report viewer, standard .rdl reports could be configured in a similar way.