Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am fresher,i was created a stored procedure for my sql table and i wanted to display those data into a aspx page..
i need the code for..ajax,js,asp.net
From the top of my head like this:
using (SqlConnection con = new SqlConnection(ConnectionString)) {
con.Open();
using (SqlCommand command = new SqlCommand("ProcedureName", con)) {
command.CommandType = CommandType.StoredProcedure;
using(SqlReader reader = command.ExecuteReader()){
if (reader.HasRows) {
while(reader.Read()) {
... process SqlReader objects...
}
}
}
}
}
EDIT: sorry, missed the "retrieve" info.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
can someone please help me re-write this line of code to parameterise the variable CMA_AAP_ID before it's passed to the GetList method?
public virtual IList<KGV_CMS_PHYSICAL_MAPPINGS> GetAssociatedPhysicalMappings()
{
return CMS_MAPPINGS.GetList(string.Format("from CMS_MAPPINGS as MAPPINGS where MAPPINGS.MAP_ID in ( select MAP_ID from FIELD_MAP_APP as FieldsAppls where FMA_APP_ID = {0} )", CMA_APP_ID));
}
You can try the following:
string sqlQuery = "from CMS_MAPPINGS as MAPPINGS where MAPPINGS.MAP_ID in ( select MAP_ID from FIELD_MAP_APP as FieldsAppls where FMA_APP_ID = #id";
then try the following:
using (var connection = new SqlConnection(/* some connection info */))
using (var command = new SqlCommand(sql, connection))
{
var idParameter = new SqlParameter("id", SqlDbType.int); // change here
idParameter.Value = 10;
command.Parameters.Add(idParameter);
var results = command.ExecuteReader();
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am using parameterised query but I got an error - how can I solve it?
Here is my code
SqlCommand cmd = new SqlCommand();
string sql = #"insert into Student_Records (FirstName,LastName,Email,ContactNumber,DOB,TemporaryAddress,PermanentAddress,FatherName,Fathersoccupation,ContactNumberF,MotherName,Mothersoccupation,ContactNumberM,Remarks) values(#firstname,#lastname,#email,#contactnumber,#dob,#temporaryaddress,#permanentaddress,#fathername,#fatheroccupation,#contactnumberf,#mothername,#motheroccupation,#contactnumberm,#remarks) ";
cmd.Parameters.AddWithValue("#firstname", txtFname.Text);
cmd.Parameters.AddWithValue("#lastname", txtlastN.Text);
cmd.Parameters.AddWithValue("#contactnumber", txtCN.Text);
cmd.Parameters.AddWithValue("#dob", dtdob.Value);
cmd.Parameters.AddWithValue("#temporaryaddress", txtTaddress.Text);
cmd.Parameters.AddWithValue("#permanentaddress", txtPaddress.Text);
cmd.Parameters.AddWithValue("#fathername", txtFname.Text);
cmd.Parameters.AddWithValue("#fatheroccupation", txtFoccupation.Text);
cmd.Parameters.AddWithValue("#contactnumberf", txtFcn.Text);
cmd.Parameters.AddWithValue("#mothername", txtMname.Text);
cmd.Parameters.AddWithValue("#motheroccoupation", txtMoccupation.Text);
cmd.Parameters.AddWithValue("#contactnumberm", txtMcn);
cmd.Parameters.AddWithValue("#remarks", rtremarks.Text);
DBconnection.ExecutiveNonQuery(sql);
I get this error:
must declare the scalar variable
using (SqlCommand cmd = new SqlCommand("Add your insert cmd", connection)) {
cmd.Parameters.AddWithValue("#firstname", txtFname.Text);
....
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm using below code but, it's giving me an error.
private void ma2()
{
try
{
string query = "select k7 from kholy1";
SqlCommand cmd = new SqlCommand(query, con);
cmd.CommandText = query;
con.Open();
SqlDataReader drd = cmd.ExecuteReader();
while (drd.Read())
{
comboBox5.Items.Add(drd.GetValue(0).ToString());
}
drd.Close();
}
catch
{
MessageBox.Show("Error ");
}
}
I'm getting an error while displaying the form!
You just simply use combo box tasks and check use Data Bound Items that's how you are able to connect it to sql database. Value member use to store it's value in database and Display Member use to Display value in front end.
You can use selected value using combobox1.SelectedValue.
Reference- Binding WPF ComboBox to a Custom List
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I search on the net to execute oracle stored function and get the value of it
and I found something similar to this but i don't really understand it so i am not able to find out what's the error with it... please if someone can explan
whats happening after opening the connection with the database ?
public void Get_Office_Desc()
{
string oradb = "Data Source=mysource;User Id=emp;Password=00;";
var v_Office_code = Current_Office_code.Text;
string CommandStr = "F_Get_Office_Desc(:pOfficeCode)";
using (OracleConnection conn = new OracleConnection(oradb))
using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OracleParameter("pOfficeCode", v_Office_code));
cmd.Parameters.Add("pOfficeDesc", OracleType.Char, 128);
cmd.Parameters["pOfficeDesc"].Direction = ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
var pOfficeDesc = Convert.ToString(cmd.Parameters["pOfficeDesc"].Value);
messagebox.show(pOfficeDesc);
}
}
You need to set CommandType to StoredProcedure - like that:
cmd.CommandType = CommandType.StoredProcedure;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a requirement where I have to perform bulk update of records in Oracle using c#. I'm trying to achieve this by passing an array of record ids that have to be updated back to oracle,but the code is not working.
The latest code that I have used is-
List<Int64> listTransId = new List<Int64>();
while (reader.Read())
{
listTransId.Add(Convert.ToInt64(reader["TOLL_TX_SEQ_NUM"]));
}
Int64[] arrTOLL_TX_SEQ_NUM = new Int64[listTransId.Count];
arrTOLL_TX_SEQ_NUM = listTransId.ToArray();
OracleTransaction txn = connection.BeginTransaction(IsolationLevel.ReadCommitted);
OracleCommand updateCmd = new OracleCommand(#" BEGIN UPDATE TOLL_TRANSACTION SET CCH_EXPORT_DATETIME = SYSDATE WHERE TOLL_TX_SEQ_NUM = :TOLL_TX_SEQ_NUM; END;");
updateCmd.CommandType = CommandType.Text;
updateCmd.Connection = connection;
//update Cmd.BindByName = true;
update Cmd.ArrayBindCount = arrTOLL_TX_SEQ_NUM.Length;
OracleParameter TOLL_TX_SEQ_NUM = new OracleParameter("TOLL_TX_SEQ_NUM", OracleDbType.Int64);
TOLL_TX_SEQ_NUM.Direction = ParameterDirection.Input;
TOLL_TX_SEQ_NUM.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
TOLL_TX_SEQ_NUM.Value = arrTOLL_TX_SEQ_NUM;
TOLL_TX_SEQ_NUM.Size = arrTOLL_TX_SEQ_NUM.Length;
updateCmd.Parameters.Add(TOLL_TX_SEQ_NUM);
Console.WriteLine("Connection state - " + connection.State);
updateCmd.ExecuteNonQuery();
txn.Commit();
connection.Close();
use "array binding" with a simply update statement.
http://www.oracle.com/technetwork/issue-archive/2009/09-sep/o59odpnet-085168.html