Make a database management system for survey (part-2)

it is the continuation of a previous post

I use oracle connection. in c# for oracle connection  i have to use one dll name  using System.Data.OracleClient; and connection code is

public static bool setConnection(string userId, string pass, string hostStr)
{
try
{
string connectStr = "Data Source=" + hostStr + ";Persist Security Info=True;User ID=" + userId + ";Password=" + pass + ";Unicode=True";
oracleConect = new OracleConnection(connectStr);
oracleConect.Open();
oraCommand = oracleConect.CreateCommand();
return true;
}
catch (OracleException oraxpr1)
{
return false;
}
Console.WriteLine("Connected...");
}

for inserting data i have to write code like

 string connectStr = "Data Source=" + "xe" + ";Persist Security Info=True;User ID=" + "userid" + ";Password=" + "pass" + ";Unicode=True";
            oracleConect = new OracleConnection(connectStr);
            oracleConect.Open();
            oraCommand = oracleConect.CreateCommand();
oraCommand.CommandText= "insert into  question values(" + "qe.nextval" + ",'" + richTextBox1.Text.ToString() + "')";
                    oraCommand.ExecuteNonQuery();
                    oraCommand.CommandText = "commit";
                    oraCommand.ExecuteNonQuery();

Foe searching data i have to write code like

          oracleConect = new OracleConnection(connectStr);
            oracleConect.Open();
            oraCommand = oracleConect.CreateCommand();
            InitializeComponent();
            oraCommand.CommandText = "select * from question ";
               OracleDataReader reader = oraCommand.ExecuteReader();
           while (reader.Read())
            {
                string retId = reader["descrip"].ToString();
                listBox1.Items.Add(retId);
            }

for delete i have to write code

oraCommand.CommandText = "delete from answer where ansid ='"+ans"'";
oraCommand.ExecuteNonQuery();
oraCommand.CommandText = "commit";
oraCommand.ExecuteNonQuery();

in next blog i will show how different type of search worked in c# oracle

Advertisements

About kishordgupta

A software developer
This entry was posted in C#, DATABASE, Winform app and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

One Response to Make a database management system for survey (part-2)

  1. I have learn a few just right stuff here. Certainly value bookmarking for revisiting.
    I surprise how much attempt you place to make this type of wonderful informative website.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s